aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-02-18 09:13:43 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-02-18 09:13:43 +0100
commit2b020f53230f57f4f44029aceee95ca484485235 (patch)
treecbcba21f77b6543c747c0e94187dbab85532488a /gdb/testsuite
parentec51c7ce9fb0a8c4b891cc67658c225be23e6820 (diff)
downloadbinutils-2b020f53230f57f4f44029aceee95ca484485235.zip
binutils-2b020f53230f57f4f44029aceee95ca484485235.tar.gz
binutils-2b020f53230f57f4f44029aceee95ca484485235.tar.bz2
testsuite, mi: prevent buffer overflow in get_mi_thread_list
If there is a large number of threads in the input program, the expect buffer in `get_mi_thread_list` would become full. Prevent this by consuming the buffer in small pieces. Regression-tested using the gdb.mi tests. Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/lib/mi-support.exp51
1 files changed, 26 insertions, 25 deletions
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index c976fa1..206971c 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1953,39 +1953,40 @@ proc mi_run_inline_test { testcase } {
}
proc get_mi_thread_list {name} {
- global expect_out
-
# MI will return a list of thread ids:
#
# -thread-list-ids
- # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
+ # ^done,thread-ids={thread-id="1",thread-id="2",...},number-of-threads="N"
# (gdb)
- mi_gdb_test "-thread-list-ids" \
- {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
- "-thread_list_ids ($name)"
-
- set output {}
- if {[info exists expect_out(buffer)]} {
- set output $expect_out(buffer)
- }
-
+ #
+ # In case there are too many threads, the expect buffer would
+ # become full. Process the buffer contents in small chunks.
set thread_list {}
- if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
- fail "finding threads in MI output ($name)"
- } else {
- pass "finding threads in MI output ($name)"
-
- # Make list of console threads
- set start [expr {[string first \{ $threads] + 1}]
- set end [expr {[string first \} $threads] - 1}]
- set threads [string range $threads $start $end]
- foreach thread [split $threads ,] {
- if {[scan $thread {thread-id="%d"} num]} {
- lappend thread_list $num
- }
+ set num_threads "unknown"
+ set test "$name: get MI thread list"
+ gdb_test_multiple "-thread-list-ids" $test -prompt "$::mi_gdb_prompt" {
+ -re "done,thread-ids=\{" {
+ exp_continue
+ }
+ -re "^thread-id=\"($::decimal)\"(,|\})" {
+ lappend thread_list $expect_out(1,string)
+ exp_continue
+ }
+ -re "^,current-thread-id=\"$::decimal\"" {
+ exp_continue
+ }
+ -re "^,number-of-threads=\"($::decimal)\"" {
+ set num_threads $expect_out(1,string)
+ exp_continue
+ }
+ -re "^\r\n$::mi_gdb_prompt" {
+ pass $gdb_test_name
}
}
+ gdb_assert {[llength $thread_list] == $num_threads} \
+ "$name: found thread ids in MI output"
+
return $thread_list
}