diff --git a/subprojects/rzgdb/include/gdbclient/responses.h b/subprojects/rzgdb/include/gdbclient/responses.h index 833aa38891..8c9c2b2c72 100644 --- a/subprojects/rzgdb/include/gdbclient/responses.h +++ b/subprojects/rzgdb/include/gdbclient/responses.h @@ -30,7 +30,7 @@ int handle_setbp(libgdbr_t *g); int handle_removebp(libgdbr_t *g); int handle_attach(libgdbr_t *g); int handle_vFile_open(libgdbr_t *g); -int handle_vFile_pread(libgdbr_t *g, ut8 *buf); +int handle_vFile_pread(libgdbr_t *g, ut8 *buf, size_t buf_len); int handle_vFile_close(libgdbr_t *g); int handle_stop_reason(libgdbr_t *g); diff --git a/subprojects/rzgdb/src/gdbclient/core.c b/subprojects/rzgdb/src/gdbclient/core.c index 296041f47c..6366232ada 100644 --- a/subprojects/rzgdb/src/gdbclient/core.c +++ b/subprojects/rzgdb/src/gdbclient/core.c @@ -1546,7 +1546,7 @@ int gdbr_pread_file(libgdbr_t *g, ut8 *buf, ut64 max_len, uint32_t start_offset) ret = -1; goto end; } - if ((ret1 = handle_vFile_pread(g, buf + ret)) < 0) { + if ((ret1 = handle_vFile_pread(g, buf + ret, max_len - ret)) < 0) { ret = ret1; goto end; } diff --git a/subprojects/rzgdb/src/gdbclient/responses.c b/subprojects/rzgdb/src/gdbclient/responses.c index 3ddff5d597..ca594d1060 100644 --- a/subprojects/rzgdb/src/gdbclient/responses.c +++ b/subprojects/rzgdb/src/gdbclient/responses.c @@ -142,7 +142,7 @@ int handle_vFile_open(libgdbr_t *g) { return send_ack(g); } -int handle_vFile_pread(libgdbr_t *g, ut8 *buf) { +int handle_vFile_pread(libgdbr_t *g, ut8 *buf, size_t buf_len) { send_ack(g); char *ptr; int len; @@ -163,6 +163,8 @@ int handle_vFile_pread(libgdbr_t *g, ut8 *buf) { // Again, this is probably the end of file if (len == 0) { return 0; + } else if (len > buf_len) { + len = buf_len; } if (!(ptr = strchr(g->data, ';')) || ptr >= g->data + g->data_len) { return -1;