From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mukesh Rathor Subject: [PATCH] gdbsx: malloc extra bye for null char Date: Fri, 16 Oct 2009 16:24:29 -0700 Message-ID: <20091016162429.0b034fc4@mantra.us.oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "Xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org Well, that didn't take long for someone to break gdbsx :). Attached and included is a fix to allocate extra byte for null char. thanks mukesh # HG changeset patch # User Mukesh Rathor # Date 1255735260 25200 # Node ID 231c46fef5c5efc177cf18606a7e99c6591cba35 # Parent 0705efd9c69e2e254c85bc4381166b7f9cfb8ee3 malloc extra bye for null char. Signed-off-by: Mukesh Rathor diff -r 0705efd9c69e -r 231c46fef5c5 tools/debugger/gdbsx/gx/gx_comm.c --- a/tools/debugger/gdbsx/gx/gx_comm.c Fri Oct 16 09:04:53 2009 +0100 +++ b/tools/debugger/gdbsx/gx/gx_comm.c Fri Oct 16 16:21:00 2009 -0700 @@ -299,6 +299,7 @@ if (write(remote_fd, buf2, p - buf2) != p - buf2) { perror("putpkt(write)"); + free(buf2); return -1; } if (gx_remote_dbg) diff -r 0705efd9c69e -r 231c46fef5c5 tools/debugger/gdbsx/gx/gx_main.c --- a/tools/debugger/gdbsx/gx/gx_main.c Fri Oct 16 09:04:53 2009 +0100 +++ b/tools/debugger/gdbsx/gx/gx_main.c Fri Oct 16 16:21:00 2009 -0700 @@ -201,7 +201,7 @@ gx_decode_m_packet(&remote_buf[1], &addr, &len); - if ((xbuf=malloc(len)) == NULL) { + if ((xbuf=malloc(len+1)) == NULL) { gx_reply_error(remote_buf); return; } @@ -227,7 +227,7 @@ data_strtp = gx_decode_M_packet(&remote_buf[1], &addr, &len); - if ((xbuf=malloc(len)) == NULL) { + if ((xbuf=malloc(len+1)) == NULL) { gx_reply_error(remote_buf); return; }