Skip to content

Commit 4b6dc87

Browse files
committed
Validate raw call addresses and faster quote strip ##shell
1 parent fb9796e commit 4b6dc87

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

libr/core/cmd.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,28 +3946,36 @@ static int handle_command_call(RCore *core, const char *cmd) {
39463946
if (isaddr || r_str_startswith (cmd, "0x")) {
39473947
int res = 1;
39483948
char *arg = strdup (cmd);
3949-
char *end = strstr (arg, "'");
3949+
char *end = arg? strchr (arg, '\''): NULL;
39503950
if (end) {
39513951
*end = 0;
3952-
cmd = end + 1;
3953-
ut64 addr = core->addr;
39543952
ut64 at = r_num_math (core->num, arg);
3955-
r_core_seek (core, at, true);
3956-
res = r_core_call (core, cmd);
3957-
r_core_seek (core, addr, true);
3958-
free (arg);
3953+
if (core->num->nc.errors) {
3954+
R_LOG_ERROR ("Invalid address '%s'", arg);
3955+
r_core_return_code (core, 1);
3956+
} else {
3957+
ut64 addr = core->addr;
3958+
r_core_seek (core, at, true);
3959+
res = r_core_call (core, end + 1);
3960+
r_core_seek (core, addr, true);
3961+
}
39593962
} else {
39603963
R_LOG_ERROR ("Invalid syntax, expected \"'@addr'command\"");
3961-
free (arg);
3964+
r_core_return_code (core, 1);
39623965
}
3966+
free (arg);
39633967
return res;
39643968
}
39653969
return r_core_call (core, cmd);
39663970
}
39673971

39683972
static void remove_leading_empty_quotes(char *cmd) {
3969-
while (r_str_startswith (cmd, "\"\"")) {
3970-
memmove (cmd, cmd + 2, strlen (cmd + 2) + 1);
3973+
char *p = cmd;
3974+
while (r_str_startswith (p, "\"\"")) {
3975+
p += 2;
3976+
}
3977+
if (p != cmd) {
3978+
memmove (cmd, p, strlen (p) + 1);
39713979
}
39723980
}
39733981

0 commit comments

Comments
 (0)