Skip to content

Commit 5897f30

Browse files
authored
Fix a buffer overflow in gdbr_parse_processes_xml (#5973)
* Fix a buffer overflow in gdbr_parse_processes_xml, and added a regression test for it
1 parent 5a2e57b commit 5897f30

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

subprojects/rzgdb/src/gdbclient/xml.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) {
361361
</osdata>
362362
*/
363363
static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int pid, RzList *list) {
364-
char pidstr[MAX_PID_CHARS + 1], status[1024], cmdline[1024];
364+
char pidstr[MAX_PID_CHARS + 1], status[1024], cmdline[4096];
365365
char *itemstr, *column, *column_end, *proc_filename;
366366
int ret = -1, ipid, column_data_len;
367367
RzDebugPid *pid_info = NULL;
@@ -408,8 +408,7 @@ static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int
408408

409409
column += sizeof("<column name=\"command\">") - 1;
410410
column_data_len = column_end - column;
411-
412-
memcpy(cmdline, column, column_data_len);
411+
memcpy(cmdline, column, RZ_MIN(column_data_len, sizeof(cmdline)));
413412
cmdline[column_data_len] = '\0';
414413

415414
// Attempt to read the pid's info from /proc. Non UNIX systems will have the

test/db/archos/linux-x64/dbg_gdbserver

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ EXPECT=<<EOF
1313
0x0
1414
EOF
1515
RUN
16+
17+
NAME=gdbserver dp
18+
FILE=bins/elf/analysis/pie
19+
CMDS=<<EOF
20+
!scripts/gdbserver.py --port 12346 --multi --binary bins/elf/analysis/pie
21+
oodf gdb://127.0.0.1:12346
22+
dp
23+
EOF
24+
REGEXP_FILTER_OUT=(^\s*[*-]\s*(\d+\s+ppid:\d+\s+uid:\d+))
25+
EXPECT=<<EOF
26+
- 1 ppid:0 uid:0
27+
EOF
28+
RUN

test/scripts/gdbserver.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ def main():
4040
action="store_true",
4141
help="print stdout output from gdbserver",
4242
)
43+
parser.add_argument(
44+
"--multi",
45+
default=False,
46+
action="store_true",
47+
help="start gdbserver in multi-process (extended-remote) mode",
48+
)
4349
args = parser.parse_args()
4450

4551
while True:
46-
for output in execute(
47-
["gdbserver", "{}:{}".format(args.host, args.port), args.binary]
48-
):
52+
cmd = ["gdbserver"]
53+
if args.multi:
54+
cmd.append("--multi") # --multi comes before HOST:PORT
55+
cmd.append(f"{args.host}:{args.port}")
56+
if args.binary:
57+
cmd.append(args.binary)
58+
for output in execute(cmd):
4959
if args.output:
5060
print(output)
5161
# Exit once gdbserver is ready for connections

0 commit comments

Comments
 (0)