diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 2764d28f59..ef497492d9 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2015-08-19 Gary Benson + + * hostio.c (handle_pread): Do not attempt to read more data + than hostio_reply_with_data can fit in a packet. + 2015-08-18 Joel Brobecker * linux-aarch32-low.c (NT_ARM_VFP): Define if not already defined. diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c index b38a6bd056..8788f07391 100644 --- a/gdb/gdbserver/hostio.c +++ b/gdb/gdbserver/hostio.c @@ -344,6 +344,7 @@ handle_pread (char *own_buf, int *new_packet_len) { int fd, ret, len, offset, bytes_sent; char *p, *data; + static int max_reply_size = -1; p = own_buf + strlen ("vFile:pread:"); @@ -359,6 +360,17 @@ handle_pread (char *own_buf, int *new_packet_len) return; } + /* Do not attempt to read more than the maximum number of bytes + hostio_reply_with_data can fit in a packet. We may still read + too much because of escaping, but this is handled below. */ + if (max_reply_size == -1) + { + sprintf (own_buf, "F%x;", PBUFSIZ); + max_reply_size = PBUFSIZ - strlen (own_buf); + } + if (len > max_reply_size) + len = max_reply_size; + data = xmalloc (len); #ifdef HAVE_PREAD ret = pread (fd, data, len, offset);