[RFA] Avoid calling stat with empty name in relocate_gdb_directory

Pierre Muller pierre.muller@ics-cnrs.unistra.fr
Wed Dec 5 17:02:00 GMT 2012


  With the troubles that I have with my patch,
I started looking into a memory debugger...
  I finally started to use drmemory
for mingw compiled GDB executables.

  This tool reports
Error #1: UNADDRESSABLE ACCESS: reading 0x01fb3a21-0x01fb3a22 1 byte(s)
# 0 msvcrt.dll!_stat32   
# 1 relocate_gdb_directory               [../../puresrc/gdb/main.c:129]
# 2 captured_main                        [../../puresrc/gdb/main.c:391]
# 3 catch_errors
[../../puresrc/gdb/exceptions.c:546]
# 4 gdb_main                             [../../puresrc/gdb/main.c:1041]
# 5 main                                 [../../puresrc/gdb/gdb.c:34]
Note: @0:00:00.733 in thread 6596
Note: refers to 1 byte(s) beyond last valid byte in prior malloc
Note: prev lower malloc:  0x01fb3a20-0x01fb3a21
Note: instruction: cmp    0x01(%edi) $0x3a

line 129 of main.c is:
  if (stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))

The unauthorized access is due to a call to stat function with dir = ""
it seems that dir[1] is access despite the fact that (dir[0]=='\0')

  I don't know if stat is supposed to handle (*dir == '\0'),
but I thought that it should anyhow succeed in that case,
so the patch below simply don't call stat if name is empty.

  Tell me if you rather think that this is a msvcrt bug that
should not be fixed in GDB...


Pierre Muller
GDB pascal language maintainer


2012-12-05  Pierre Muller  <muller@sourceware.org>

        * main.c (relocate_gdb_directory): Avoid calling stat function
        if DIR is empty.

Index: src/gdb/main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.115
diff -u -p -r1.115 main.c
--- src/gdb/main.c      16 Nov 2012 19:43:38 -0000      1.115
+++ src/gdb/main.c      5 Dec 2012 16:54:40 -0000
@@ -126,7 +126,7 @@ relocate_gdb_directory (const char *init
     {
       struct stat s;

-      if (stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
+      if (*dir == '\0' || stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
        {
          xfree (dir);
          dir = NULL;
~



More information about the Gdb-patches mailing list