mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Fix handling of '' and "".
This commit is contained in:
parent
3e2ab88ee2
commit
be66ad3212
10
lash.c
10
lash.c
@ -1159,7 +1159,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
int argc_l = 0;
|
int argc_l = 0;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int argv_alloced;
|
int argv_alloced;
|
||||||
int i;
|
int i, saw_quote = 0;
|
||||||
char quote = '\0';
|
char quote = '\0';
|
||||||
int count;
|
int count;
|
||||||
struct child_prog *prog;
|
struct child_prog *prog;
|
||||||
@ -1221,7 +1221,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
*src == ']') *buf++ = '\\';
|
*src == ']') *buf++ = '\\';
|
||||||
*buf++ = *src;
|
*buf++ = *src;
|
||||||
} else if (isspace(*src)) {
|
} else if (isspace(*src)) {
|
||||||
if (*prog->argv[argc_l]) {
|
if (*prog->argv[argc_l] || saw_quote) {
|
||||||
buf++, argc_l++;
|
buf++, argc_l++;
|
||||||
/* +1 here leaves room for the NULL which ends argv */
|
/* +1 here leaves room for the NULL which ends argv */
|
||||||
if ((argc_l + 1) == argv_alloced) {
|
if ((argc_l + 1) == argv_alloced) {
|
||||||
@ -1231,12 +1231,14 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
argv_alloced);
|
argv_alloced);
|
||||||
}
|
}
|
||||||
prog->argv[argc_l] = buf;
|
prog->argv[argc_l] = buf;
|
||||||
|
saw_quote = 0;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
switch (*src) {
|
switch (*src) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
quote = *src;
|
quote = *src;
|
||||||
|
saw_quote = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#': /* comment */
|
case '#': /* comment */
|
||||||
@ -1305,7 +1307,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
|
|
||||||
case '|': /* pipe */
|
case '|': /* pipe */
|
||||||
/* finish this command */
|
/* finish this command */
|
||||||
if (*prog->argv[argc_l])
|
if (*prog->argv[argc_l] || saw_quote)
|
||||||
argc_l++;
|
argc_l++;
|
||||||
if (!argc_l) {
|
if (!argc_l) {
|
||||||
error_msg("empty command in pipe");
|
error_msg("empty command in pipe");
|
||||||
@ -1474,7 +1476,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*prog->argv[argc_l]) {
|
if (*prog->argv[argc_l] || saw_quote) {
|
||||||
argc_l++;
|
argc_l++;
|
||||||
}
|
}
|
||||||
if (!argc_l) {
|
if (!argc_l) {
|
||||||
|
10
sh.c
10
sh.c
@ -1159,7 +1159,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
int argc_l = 0;
|
int argc_l = 0;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int argv_alloced;
|
int argv_alloced;
|
||||||
int i;
|
int i, saw_quote = 0;
|
||||||
char quote = '\0';
|
char quote = '\0';
|
||||||
int count;
|
int count;
|
||||||
struct child_prog *prog;
|
struct child_prog *prog;
|
||||||
@ -1221,7 +1221,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
*src == ']') *buf++ = '\\';
|
*src == ']') *buf++ = '\\';
|
||||||
*buf++ = *src;
|
*buf++ = *src;
|
||||||
} else if (isspace(*src)) {
|
} else if (isspace(*src)) {
|
||||||
if (*prog->argv[argc_l]) {
|
if (*prog->argv[argc_l] || saw_quote) {
|
||||||
buf++, argc_l++;
|
buf++, argc_l++;
|
||||||
/* +1 here leaves room for the NULL which ends argv */
|
/* +1 here leaves room for the NULL which ends argv */
|
||||||
if ((argc_l + 1) == argv_alloced) {
|
if ((argc_l + 1) == argv_alloced) {
|
||||||
@ -1231,12 +1231,14 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
argv_alloced);
|
argv_alloced);
|
||||||
}
|
}
|
||||||
prog->argv[argc_l] = buf;
|
prog->argv[argc_l] = buf;
|
||||||
|
saw_quote = 0;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
switch (*src) {
|
switch (*src) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
quote = *src;
|
quote = *src;
|
||||||
|
saw_quote = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#': /* comment */
|
case '#': /* comment */
|
||||||
@ -1305,7 +1307,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
|
|
||||||
case '|': /* pipe */
|
case '|': /* pipe */
|
||||||
/* finish this command */
|
/* finish this command */
|
||||||
if (*prog->argv[argc_l])
|
if (*prog->argv[argc_l] || saw_quote)
|
||||||
argc_l++;
|
argc_l++;
|
||||||
if (!argc_l) {
|
if (!argc_l) {
|
||||||
error_msg("empty command in pipe");
|
error_msg("empty command in pipe");
|
||||||
@ -1474,7 +1476,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*prog->argv[argc_l]) {
|
if (*prog->argv[argc_l] || saw_quote) {
|
||||||
argc_l++;
|
argc_l++;
|
||||||
}
|
}
|
||||||
if (!argc_l) {
|
if (!argc_l) {
|
||||||
|
10
shell/lash.c
10
shell/lash.c
@ -1159,7 +1159,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
int argc_l = 0;
|
int argc_l = 0;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int argv_alloced;
|
int argv_alloced;
|
||||||
int i;
|
int i, saw_quote = 0;
|
||||||
char quote = '\0';
|
char quote = '\0';
|
||||||
int count;
|
int count;
|
||||||
struct child_prog *prog;
|
struct child_prog *prog;
|
||||||
@ -1221,7 +1221,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
*src == ']') *buf++ = '\\';
|
*src == ']') *buf++ = '\\';
|
||||||
*buf++ = *src;
|
*buf++ = *src;
|
||||||
} else if (isspace(*src)) {
|
} else if (isspace(*src)) {
|
||||||
if (*prog->argv[argc_l]) {
|
if (*prog->argv[argc_l] || saw_quote) {
|
||||||
buf++, argc_l++;
|
buf++, argc_l++;
|
||||||
/* +1 here leaves room for the NULL which ends argv */
|
/* +1 here leaves room for the NULL which ends argv */
|
||||||
if ((argc_l + 1) == argv_alloced) {
|
if ((argc_l + 1) == argv_alloced) {
|
||||||
@ -1231,12 +1231,14 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
argv_alloced);
|
argv_alloced);
|
||||||
}
|
}
|
||||||
prog->argv[argc_l] = buf;
|
prog->argv[argc_l] = buf;
|
||||||
|
saw_quote = 0;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
switch (*src) {
|
switch (*src) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
quote = *src;
|
quote = *src;
|
||||||
|
saw_quote = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#': /* comment */
|
case '#': /* comment */
|
||||||
@ -1305,7 +1307,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
|
|
||||||
case '|': /* pipe */
|
case '|': /* pipe */
|
||||||
/* finish this command */
|
/* finish this command */
|
||||||
if (*prog->argv[argc_l])
|
if (*prog->argv[argc_l] || saw_quote)
|
||||||
argc_l++;
|
argc_l++;
|
||||||
if (!argc_l) {
|
if (!argc_l) {
|
||||||
error_msg("empty command in pipe");
|
error_msg("empty command in pipe");
|
||||||
@ -1474,7 +1476,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*prog->argv[argc_l]) {
|
if (*prog->argv[argc_l] || saw_quote) {
|
||||||
argc_l++;
|
argc_l++;
|
||||||
}
|
}
|
||||||
if (!argc_l) {
|
if (!argc_l) {
|
||||||
|
Loading…
Reference in New Issue
Block a user