From patchwork Thu Feb 29 15:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 86597 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88D673858C53 for ; Thu, 29 Feb 2024 15:50:09 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by sourceware.org (Postfix) with ESMTPS id C1AB0385840F for ; Thu, 29 Feb 2024 15:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1AB0385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C1AB0385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709221783; cv=none; b=CimfSi41lfu+ShDET9YuPPk29y3KnIUKru4Uj/8dWvYT6BfwjLQJVdYjFqmQsyHkGldqOQfc7fICVAEhDDJmixRE+ukzFPMK7J2ivCYHmdvZkun88z7y7zetQfikcspWHCzf1uaCGVP1tYLIslCSNgiKP9VUBluX/x7Rf1SBwE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709221783; c=relaxed/simple; bh=54H4ii0n4nrEaFHdBGODEeKxyzaXU7jKljneZhne47s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=sYv2ZE7xDtUhQRJYHia9ruCSEbLc2+6UrJ/8qJ0iBwuggsLdz2Lignz4AZKYrnGUYYDXIhQFTqG2BpbQVK9O0iX5XaBogxyqahkjJExMl4y1GYM9uuxBsfI8AnFUS1yRQFwRKSeRLoH2cDIBo6X1uRnMlXWs4fLDfgpS8+JpnLY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709221781; x=1740757781; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=54H4ii0n4nrEaFHdBGODEeKxyzaXU7jKljneZhne47s=; b=BGSamBsOHjBi1cmK3tQxHT/H+Gc23bxvFsCxwUo/vDymkcwDQtsnQLEJ mv1dzsOqOeHVPx6HCqXKeC3hNsOu+nkMXm0i0Egp1kWsMQ8Gb46wkt/IR 6SAK5NIvPa3XxB7ZZSMV8EBndO3jlWluk39UubLwmF5tfA4Z0PVnWgb0l wk4V6DcmlDdAyh6LdsrI6leCgTXMej5E9CsRGx4qtm14kG/UnPTEWvxsJ 6XUJAytUj/u6lzB2hyE3brmhk3ml9gFGvUl+RkKbGg3COjtXWqKlzTVfE OA0fzN8MtSLCo16BAVkHJPVLqU6ZzB62hZroL3Td0DCeU4MzO4HExEX+Y w==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="3819327" X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="3819327" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 07:49:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,194,1705392000"; d="scan'208";a="7902935" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Feb 2024 07:49:30 -0800 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH v2 2/2] testsuite, mi: prevent buffer overflow in get_mi_thread_list Date: Thu, 29 Feb 2024 16:49:06 +0100 Message-Id: <20240229154906.3354860-2-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229154906.3354860-1-tankut.baris.aktemur@intel.com> References: <20240229154906.3354860-1-tankut.baris.aktemur@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org For the first version of this patch, Linaro's bot reported regression: https://ci.linaro.org/job/tcwg_gdb_check--master-arm-precommit/1788/artifact/artifacts/artifacts.precommit/notify/mail-body.txt I cannot reproduce the failure locally. In this revision, I added the "-prompt" flag to gdb_test_multiple. Hopefully that will help address the failure reported by the bot. The first version is available at https://sourceware.org/pipermail/gdb-patches/2024-February/206885.html Regards, Baris ================================= 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. --- gdb/testsuite/lib/mi-support.exp | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index 33a3a71b396..6862b831c07 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -1953,39 +1953,43 @@ proc mi_run_inline_test { testcase } { } proc get_mi_thread_list {name} { - global expect_out + global expect_out decimal mi_gdb_prompt # 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)\"(,|\})" { + set num $expect_out(1,string) + lappend thread_list $num + 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 }