Use rs->buf after getpkt
authorYao Qi <yao@codesourcery.com>
Mon, 20 Jan 2014 12:56:13 +0000 (20:56 +0800)
committerYao Qi <yao@codesourcery.com>
Wed, 5 Feb 2014 12:25:47 +0000 (20:25 +0800)
Hi,
The following code snippet looks wrong to me

 char *buf = rs->buf;

 getpkt (&rs->buf, &rs->buf_size, 0);
 packet_ok (buf, );

if rs->buf is reallocated in getpkt, buf points to an out of dated
memory.  This patch removes local 'buf' and uses rs->buf.

gdb:

2014-02-05  Yao Qi  <yao@codesourcery.com>

* remote.c (remote_pass_signals): Remove local 'buf' and use
rs->buf.
(remote_program_signals): Likewise.

gdb/ChangeLog
gdb/remote.c

index 73e87749d7c4bd29542c9050cc9e93f0a254b3e7..a6fa6fcd4dd4795a71576c3abdabdfdbd81e7c45 100644 (file)
@@ -1,3 +1,9 @@
+2014-02-05  Yao Qi  <yao@codesourcery.com>
+
+       * remote.c (remote_pass_signals): Remove local 'buf' and use
+       rs->buf.
+       (remote_program_signals): Likewise.
+
 2014-02-05  Yao Qi  <yao@codesourcery.com>
 
        * ctf.c: Include "inferior.h" and "gdbthread.h".
index 4227ed5b307f587da8b8e155082c9440c32b81e1..e1d0a64d2115c24aa04eb42c4312f6b877056bea 100644 (file)
@@ -1732,11 +1732,9 @@ remote_pass_signals (int numsigs, unsigned char *pass_signals)
       *p = 0;
       if (!rs->last_pass_packet || strcmp (rs->last_pass_packet, pass_packet))
        {
-         char *buf = rs->buf;
-
          putpkt (pass_packet);
          getpkt (&rs->buf, &rs->buf_size, 0);
-         packet_ok (buf, &remote_protocol_packets[PACKET_QPassSignals]);
+         packet_ok (rs->buf, &remote_protocol_packets[PACKET_QPassSignals]);
          if (rs->last_pass_packet)
            xfree (rs->last_pass_packet);
          rs->last_pass_packet = pass_packet;
@@ -1785,11 +1783,9 @@ remote_program_signals (int numsigs, unsigned char *signals)
       if (!rs->last_program_signals_packet
          || strcmp (rs->last_program_signals_packet, packet) != 0)
        {
-         char *buf = rs->buf;
-
          putpkt (packet);
          getpkt (&rs->buf, &rs->buf_size, 0);
-         packet_ok (buf, &remote_protocol_packets[PACKET_QProgramSignals]);
+         packet_ok (rs->buf, &remote_protocol_packets[PACKET_QProgramSignals]);
          xfree (rs->last_program_signals_packet);
          rs->last_program_signals_packet = packet;
        }