]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Don't copy memory for arguments if there are none
authorHannes Domani <ssbssa@yahoo.de>
Sun, 27 Oct 2024 18:30:38 +0000 (19:30 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Mon, 28 Oct 2024 20:00:12 +0000 (21:00 +0100)
If amd64_windows_push_arguments is called with no arguments, then ARGS
can be NULL, and inside the passed-by-pointer block, memcpy is called
with this NULL, which is undefined behavior.

So this just disable the passed-by-pointer block if there are no
arguments.

Fixes the following ubsan error:
C:/gdb/src/gdb.git/gdb/amd64-windows-tdep.c:244:12: runtime error: null pointer passed as argument 2, which is declared to never be null

Approved-By: Tom Tromey <tom@tromey.com>
gdb/amd64-windows-tdep.c

index 29a1f60d787403230e67939ee7dd6f45caa1b5b0..3ba2d1a7577eade3bb4b8aefecefe2835610d800 100644 (file)
@@ -238,6 +238,7 @@ amd64_windows_push_arguments (struct regcache *regcache, int nargs,
      These arguments are replaced by pointers to a copy we are making
      in inferior memory.  So use a copy of the ARGS table, to avoid
      modifying the original one.  */
+  if (nargs > 0)
   {
     struct value **args1 = XALLOCAVEC (struct value *, nargs);