From patchwork Tue Feb 27 18:04:13 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: 86466 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 56A8E3858401 for ; Tue, 27 Feb 2024 18:05:06 +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.21]) by sourceware.org (Postfix) with ESMTPS id 966FB3858D20 for ; Tue, 27 Feb 2024 18:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 966FB3858D20 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 966FB3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709057081; cv=none; b=Vd3ZQvv2/KpDR9ugi3/VN1hI+8Tu+QbqyiY61hr/oDTdTE+BvWTKxLoQs/KwChEuOJLIcg/Xsc4opvSMAySVlgYtr3fiZXt9ZpziTp+rmzBgSzg33JpogYC9wULzkkmCcSnE38LQJKOS1YBGCVdkBTZQv5JmIQUDxAZfhOsAmf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709057081; c=relaxed/simple; bh=TXN5lJUMv3KTKPz9PfDSoAa8GyVQ/dF/CIIla0clxW8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gzCHe9cL65cMvNkRfz9o0XvPOgQPWH6NU4oSesmwSrb7TIEdoDD64QZZiu3MM9zXHC19TdrhcnnvEuLUMPKqbsHzqCsBSmiD1clWiDaKCMi4x+c7Rl7blxJymyLMzYXlTIH0LZkJb2FOY9t+ODbEeWU2tfRVznPTnfOR1qbJhQM= 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=1709057079; x=1740593079; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=TXN5lJUMv3KTKPz9PfDSoAa8GyVQ/dF/CIIla0clxW8=; b=TbtCmDYnSYyzXG3lJkzi/hzl2PwR0T4yZXaRO/D9zhZXl/lmOvE0VNGC l3ZFKg8XkolJ7t/4hz4AZeePWgE4oT+fpz3V2vRYU1Wgc34XZvi56e1Hn VlhQpuMmtCyLwMmKju6GYMrnEj+yGA0+9j1vMNEAH7eLViVsgOz6Ee8VE nZ+fb03Eenee/07H1gjQu8ZYVqFBoF31YE13SxQMAIf2G1H2osk5Kz11V R/96IhBfxVWtn2yyM71F/oKSNcG5GVEcEifPeKKiVN+OxoLO9OePX6+z+ nozq35ePGEKBF63QrZkyVz8pe6Ob1ECXbu2xxEdFHuI4jCuydYkaomuiX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3337642" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3337642" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:04:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="11704303" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:04:36 -0800 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 1/2] testsuite, mi: fix indentation in get_mi_thread_list Date: Tue, 27 Feb 2024 19:04:13 +0100 Message-Id: <20240227180414.3366314-1-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-9.4 required=5.0 tests=AC_FROM_MANY_DOTS, BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 The `get_mi_thread_list` procedure's body is incorrectly indented. Fix it. One line is still too long, but we don't care to break it. The next patch will change it. --- gdb/testsuite/lib/mi-support.exp | 58 ++++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index b3a27efb155..33a3a71b396 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -1953,40 +1953,40 @@ proc mi_run_inline_test { testcase } { } proc get_mi_thread_list {name} { - global expect_out + 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" - # (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)" + # MI will return a list of thread ids: + # + # -thread-list-ids + # ^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) - } + set output {} + if {[info exists expect_out(buffer)]} { + set output $expect_out(buffer) + } - 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 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 + } + } } - } - return $thread_list + return $thread_list } # Check that MI and the console know of the same threads. From patchwork Tue Feb 27 18:04:14 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: 86467 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 99B663858404 for ; Tue, 27 Feb 2024 18:05:35 +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.21]) by sourceware.org (Postfix) with ESMTPS id 504DE3858C54 for ; Tue, 27 Feb 2024 18:04:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 504DE3858C54 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 504DE3858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709057089; cv=none; b=CoLS7lAvta3Vgp+zltR0BVz63aJVvy40XzlH0MjvT2dqnNn20LckLrpdpy7rs49QGDLxmeuG48H9HBTUH5vpHo7bgb+zNm7seBLaMIhwe0fP7qxEuxgseWqjCKHCWn4Qt6znRpzFPRSdEbUL9+gXKeaz1WyNcVxA27BJrMKVvgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709057089; c=relaxed/simple; bh=JptbsLL3kTz6HvZdfbQ841K6DdHB2ichkUwxyeT3QSU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LH29ybxVAgOaohZzrOPB+E8y9Z2kK9IjspGt3gGXA+xITDk2d4dHOxfGx8yQnSTYLYZJTHnwqfj4qqJWNXNhwhQwOnZ23PomqopbiaB2hC923tRU6mb6obA8EAJ/iVAhOUcr4E8Y/ZdEfY5zVeV/G9kOZZ+2DqMhWVL7UtDyWFo= 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=1709057087; x=1740593087; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=JptbsLL3kTz6HvZdfbQ841K6DdHB2ichkUwxyeT3QSU=; b=gS6UtsRF+Q+y/0XxeYnIrRtnryGtE1wCAQxVb3+KR0bngUI+rMousCvW c7XLmATbZgC5XoYgMo86C0m6Skqy5cHb2Vjyu6a9au3o1SkwiedWyQoS3 +OmZPq3Dx1C6/GmcCZzuUbGar85HPcRCSti9ByQ4kuLgv7ycSZ6QGZt+k kN9lvslIFsgLKNxZUgGiGXUkF1OpKt+fGVUm1kz/umbJY/1oq5+X45MVx KpwBNQyVsnWMR8FwZSkOaenM5g5qp6R6t8LO4/NGuaowseJDIXJvFsjw3 g8tis/jwpILx3dwyifUkWDN6MffhgSkmAyeqSUBSkPj6ppsFWPq5kvGEk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3337672" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3337672" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:04:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="11704376" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:04:46 -0800 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 2/2] testsuite, mi: prevent buffer overflow in get_mi_thread_list Date: Tue, 27 Feb 2024 19:04:14 +0100 Message-Id: <20240227180414.3366314-2-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227180414.3366314-1-tankut.baris.aktemur@intel.com> References: <20240227180414.3366314-1-tankut.baris.aktemur@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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 | 51 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index 33a3a71b396..bbc8bf0a297 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -1953,39 +1953,42 @@ 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" + gdb_test_multiple "-thread-list-ids" "$name: get mi thread list" { + -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 }