]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libcpu: riscv_disasm use 50 char mnebuf
authorMark Wielaard <mark@klomp.org>
Mon, 2 Jun 2025 23:50:07 +0000 (01:50 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 3 Jun 2025 11:44:54 +0000 (13:44 +0200)
Some "illegal" instructions can be up to 24 chars (192 bits), We'll
print this as 0x<48 hex chars>. So make sure the mnebuf is 50 chars
(no terminating zero is needed).

This shows up with _FORTIFY_SOURCE which would immediate terminate on
such "illegal" instructions. Without we just use a few extra bytes on
the stack (which aren't used afterwards, without any issue, even
though it is technically UB).

* libcpu/riscv_disasm.c (riscv_disasm): Extend char mnebuf
        array to 50.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libcpu/riscv_disasm.c

index 823fe9ca05616362c6dd06ac48070b16c532d692..0dee842aae53fdef5ace2f8f87c66ea1bf4e7f16 100644 (file)
@@ -164,7 +164,10 @@ riscv_disasm (Ebl *ebl,
        }
 
       char *mne = NULL;
-      char mnebuf[32];
+      /* Max length is 24, which is "illegal", so we print it as
+         "0x<48 hex chars>"
+         See: No instruction encodings defined for these sizes yet, below  */
+      char mnebuf[50];
       char *op[5] = { NULL, NULL, NULL, NULL, NULL };
       char immbuf[32];
       size_t len;