mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-19 01:19:41 +08:00
Re: LoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1">
This fixes the buffer overflow added in commit 22b78fad28, and a few
other problems.
* loongarch-coder.c (loongarch_split_args_by_comma): Don't
overflow buffer when args == "". Don't remove unbalanced
quotes. Don't trim last arg if max number of args exceeded.
This commit is contained in:
@@ -255,22 +255,24 @@ loongarch_split_args_by_comma (char *args, const char *arg_strs[])
|
||||
size_t num = 0;
|
||||
|
||||
if (*args)
|
||||
arg_strs[num++] = args;
|
||||
for (; *args; args++)
|
||||
if (*args == ',')
|
||||
{
|
||||
if (MAX_ARG_NUM_PLUS_2 - 1 == num)
|
||||
break;
|
||||
else
|
||||
*args = '\0', arg_strs[num++] = args + 1;
|
||||
}
|
||||
|
||||
if (*(args-1) == '"')
|
||||
{
|
||||
*(args-1) = '\0';
|
||||
arg_strs[num-1] = arg_strs[num-1] + 1;
|
||||
}
|
||||
arg_strs[num++] = args;
|
||||
for (; *args; args++)
|
||||
if (*args == ',')
|
||||
{
|
||||
if (MAX_ARG_NUM_PLUS_2 - 1 == num)
|
||||
goto out;
|
||||
*args = '\0';
|
||||
arg_strs[num++] = args + 1;
|
||||
}
|
||||
|
||||
if (*(args - 1) == '"' && *arg_strs[num - 1] == '"')
|
||||
{
|
||||
*(args - 1) = '\0';
|
||||
arg_strs[num - 1] += 1;
|
||||
}
|
||||
}
|
||||
out:
|
||||
arg_strs[num] = NULL;
|
||||
return num;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user