* [binutils-gdb] Re: LoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1">
@ 2023-12-24 23:55 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-12-24 23:55 UTC (permalink / raw)
To: bfd-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d120f18ef0f2844b5ae0fcf18d86f7d5647c5ad
commit 2d120f18ef0f2844b5ae0fcf18d86f7d5647c5ad
Author: Alan Modra <amodra@gmail.com>
Date: Sun Dec 24 14:41:06 2023 +1030
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.
Diff:
---
opcodes/loongarch-coder.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c
index 672a468b3f4..b68352769ca 100644
--- a/opcodes/loongarch-coder.c
+++ b/opcodes/loongarch-coder.c
@@ -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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-24 23:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-24 23:55 [binutils-gdb] Re: LoongArch: Add support for <b ".L1"> and <beq, $t0, $t1, ".L1"> Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).