mirror of https://github.com/mirror/busybox.git
Fix branching commands.
If a label isnt specified, jump to end of script, not the last command in the script. Print an error and exit if you try and jump to a non-existant label Works for the following testcase # cat strings a b c d e f g # cat strings | ./busybox sed -n '/d/b;p' a b c e f g1_00_stable_10817
parent
8aac05bfe5
commit
f4523562b6
|
@ -475,9 +475,11 @@ static char *parse_cmd_str(sed_cmd_t * sed_cmd, char *cmdstr)
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
cmdstr += strspn(cmdstr, " ");
|
cmdstr += strspn(cmdstr, " ");
|
||||||
length = strcspn(cmdstr, "; \n");
|
length = strcspn(cmdstr, semicolon_whitespace);
|
||||||
sed_cmd->label = strndup(cmdstr, length);
|
if (length) {
|
||||||
cmdstr += length;
|
sed_cmd->label = strndup(cmdstr, length);
|
||||||
|
cmdstr += length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* translation command */
|
/* translation command */
|
||||||
else if (sed_cmd->cmd == 'y') {
|
else if (sed_cmd->cmd == 'y') {
|
||||||
|
@ -771,13 +773,11 @@ static sed_cmd_t *branch_to(const char *label)
|
||||||
sed_cmd_t *sed_cmd;
|
sed_cmd_t *sed_cmd;
|
||||||
|
|
||||||
for (sed_cmd = sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) {
|
for (sed_cmd = sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) {
|
||||||
if ((sed_cmd->label) && (strcmp(sed_cmd->label, label) == 0)) {
|
if ((sed_cmd->cmd == ':') && (sed_cmd->label) && (strcmp(sed_cmd->label, label) == 0)) {
|
||||||
break;
|
return (sed_cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bb_error_msg_and_die("Can't find label for jump to `%s'", label);
|
||||||
/* If no match returns last command */
|
|
||||||
return (sed_cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_file(FILE * file)
|
static void process_file(FILE * file)
|
||||||
|
@ -998,12 +998,17 @@ static void process_file(FILE * file)
|
||||||
linenum++;
|
linenum++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
|
||||||
sed_cmd = branch_to(sed_cmd->label);
|
|
||||||
break;
|
|
||||||
case 't':
|
case 't':
|
||||||
if (substituted) {
|
if (substituted)
|
||||||
sed_cmd = branch_to(sed_cmd->label);
|
/* Fall through */
|
||||||
|
case 'b':
|
||||||
|
{
|
||||||
|
if (sed_cmd->label == NULL) {
|
||||||
|
/* Jump to end of script */
|
||||||
|
deleted = 1;
|
||||||
|
} else {
|
||||||
|
sed_cmd = branch_to(sed_cmd->label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'y':{
|
case 'y':{
|
||||||
|
|
Loading…
Reference in New Issue