This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix using uninitialised values


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6a49a997b406fba3a389d9d8a6ff72042606c69d

commit 6a49a997b406fba3a389d9d8a6ff72042606c69d
Author: Yao Qi <yao.qi@linaro.org>
Date:   Fri Jul 17 12:14:59 2015 +0100

    Fix using uninitialised values
    
    We did a code refacotr here
    https://sourceware.org/ml/gdb-patches/2013-11/msg00063.html
    
    >	(get_current_thread): New function, factored out from ...
    >	(add_current_inferior_and_thread): ... this.  Adjust.
    >
    >@@ -3332,18 +3371,8 @@ add_current_inferior_and_thread (char *wait_status)
    >
    >   inferior_ptid = null_ptid;
    >
    >-  /* Now, if we have thread information, update inferior_ptid.  First
    >-     if we have a stop reply handy, maybe it's a T stop reply with a
    >-     "thread" register we can extract the current thread from.  If
    >-     not, ask the remote which is the current thread, with qC.  The
    >-     former method avoids a roundtrip.  Note we don't use
    >-     remote_parse_stop_reply as that makes use of the target
    >-     architecture, which we haven't yet fully determined at this
    >-     point.  */
    >-  if (wait_status != NULL)
    >-    ptid = stop_reply_extract_thread (wait_status);
    >-  if (ptid_equal (ptid, null_ptid))
    >-    ptid = remote_current_thread (inferior_ptid);
    >+  /* Now, if we have thread information, update inferior_ptid.  */
    >+  ptid = get_current_thread (wait_status);
    
    but after the refactor, local variable ptid is used without
    initialisation.  However, before this change, ptid is initialised to
    null_ptid.  This error can be found by valgrind too...
    
    ==3298==    at 0x6B99BA: ptid_equal (ptid.c:80)
    ==3298==    by 0x4C67FF: get_current_thread (remote.c:3484)
    ==3298==    by 0x4C6951: add_current_inferior_and_thread (remote.c:3511)
    ==3298==    by 0x4C762C: extended_remote_create_inferior (remote.c:8506)
    ==3298==    by 0x5A5312: run_command_1 (infcmd.c:606)
    ==3298==    by 0x68B4FB: execute_command (top.c:463)
    ==3298==    by 0x5C7214: command_handler (event-top.c:494)
    ==3298==    by 0x5C78A3: command_line_handler (event-top.c:692)
    ==3298==    by 0x6DEB57: rl_callback_read_char (callback.c:220)
    ==3298==    by 0x5C7278: rl_callback_read_char_wrapper (event-top.c:171)
    ==3298==    by 0x5C72C2: stdin_event_handler (event-top.c:432)
    ==3298==    by 0x5C6194: gdb_wait_for_event (event-loop.c:834)
    
    This patch initialises local variable ptid to null in get_current_thread.
    We don't need to initialise ptid in add_current_inferior_and_thread,
    so this patch also removes the ptid initialisation.
    
    gdb:
    
    2015-07-17  Yao Qi  <yao.qi@linaro.org>
    
    	* remote.c (get_current_thread): Initialise ptid to null_ptid.
    	(add_current_inferior_and_thread): Don't initialise ptid.

Diff:
---
 gdb/ChangeLog | 5 +++++
 gdb/remote.c  | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f4857e3..646a827 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-07-17  Yao Qi  <yao.qi@linaro.org>
+
+	* remote.c (get_current_thread): Initialise ptid to null_ptid.
+	(add_current_inferior_and_thread): Don't initialise ptid.
+
 2015-07-16  Pierre Langlois  <pierre.langlois@arm.com>
 
 	* aarch64-tdep.c (aarch64_pseudo_read_value): Mark S register as
diff --git a/gdb/remote.c b/gdb/remote.c
index 9d97f6b..94899bd 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -3474,7 +3474,7 @@ stop_reply_extract_thread (char *stop_reply)
 static ptid_t
 get_current_thread (char *wait_status)
 {
-  ptid_t ptid;
+  ptid_t ptid = null_ptid;
 
   /* Note we don't use remote_parse_stop_reply as that makes use of
      the target architecture, which we haven't yet fully determined at
@@ -3503,7 +3503,7 @@ add_current_inferior_and_thread (char *wait_status)
 {
   struct remote_state *rs = get_remote_state ();
   int fake_pid_p = 0;
-  ptid_t ptid = null_ptid;
+  ptid_t ptid;
 
   inferior_ptid = null_ptid;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]