Don't copy memory for arguments if there are none

Message ID 20241027185500.571-1-ssbssa@yahoo.de
State New
Headers
Series Don't copy memory for arguments if there are none |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Hannes Domani Oct. 27, 2024, 6:55 p.m. UTC
  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
---
 gdb/amd64-windows-tdep.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Tom Tromey Oct. 28, 2024, 7:39 p.m. UTC | #1
>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:

Hannes> If amd64_windows_push_arguments is called with no arguments, then ARGS
Hannes> can be NULL, and inside the passed-by-pointer block, memcpy is called
Hannes> with this NULL, which is undefined behavior.

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

Thanks.  This is ok.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Hannes Domani Oct. 28, 2024, 8:02 p.m. UTC | #2
Am Montag, 28. Oktober 2024 um 20:39:36 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

> >>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:
>
> Hannes> If amd64_windows_push_arguments is called with no arguments, then ARGS
> Hannes> can be NULL, and inside the passed-by-pointer block, memcpy is called
> Hannes> with this NULL, which is undefined behavior.
>
> Hannes> So this just disable the passed-by-pointer block if there are no
> Hannes> arguments.
>
> Thanks.  This is ok.
> Approved-By: Tom Tromey <tom@tromey.com>

Pushed, thanks.


Hannes
  

Patch

diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index cb350cadecb..555e225219d 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -239,6 +239,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);