Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <gdb-patches@sourceware.org>
Subject: [RFA] Avoid calling stat with empty name in relocate_gdb_directory
Date: Wed, 05 Dec 2012 17:02:00 -0000	[thread overview]
Message-ID: <000001cdd30a$3dbca7c0$b935f740$@muller@ics-cnrs.unistra.fr> (raw)

  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;
~


             reply	other threads:[~2012-12-05 17:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-05 17:02 Pierre Muller [this message]
     [not found] <29503.7594777115$1354726985@news.gmane.org>
2012-12-05 18:03 ` Tom Tromey
2012-12-05 23:45   ` Pierre Muller
     [not found]   ` <434.327257289802$1354751122@news.gmane.org>
2012-12-06 18:33     ` Tom Tromey
2012-12-14  8:17       ` Pierre Muller
     [not found]       ` <26262.2907328934$1355473042@news.gmane.org>
2013-01-03 20:59         ` Tom Tromey
2013-01-03 22:19           ` Pierre Muller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001cdd30a$3dbca7c0$b935f740$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox