From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3820E3858C53 for ; Thu, 14 Apr 2022 18:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3820E3858C53 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-65-zWekklk-MuS8Z-5OAIvq2w-1; Thu, 14 Apr 2022 14:56:42 -0400 X-MC-Unique: zWekklk-MuS8Z-5OAIvq2w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F59B18E5363; Thu, 14 Apr 2022 18:56:41 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B6C7409B3E0; Thu, 14 Apr 2022 18:56:41 +0000 (UTC) From: Aaron Merey To: simon.marchi@polymtl.ca Cc: gdb-patches@sourceware.org, Aaron Merey Subject: Re: [PATCH] gdb/debuginfod: Prevent out_of_range exception Date: Thu, 14 Apr 2022 14:56:31 -0400 Message-Id: <20220414185631.28493-1-amerey@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_BADIPHTTP, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 18:56:48 -0000 Hi Simon, On Sat, Apr 9, 2022 at 11:42 AM Simon Marchi wrote: > On 2022-04-08 18:50, Aaron Merey via Gdb-patches wrote: > > -       url_view = url_view.substr (url_view.find_first_not_of (' ')); > > +       size_t off = url_view.find_first_not_of (' '); > > +       if (off == gdb::string_view::npos) > > +         break; > > +       url_view = url_view.substr (off); > >         if (url_view.empty ()) > >           break; > > > The change LGTM.  A test would be nice though, if not too complicated. I added a few first-use notice testcases. I used gdb_expect instead of gdb_test because I couldn't get gdb_test to match any text preceeding the y/n prompt in the first-use notices, including the list of URLs. I didn't have this problem with gdb_expect. > Also, I wonder if that url_view.empty() check is useful though.  Can it > really happen? I think you're right. If we get to that check then there must be at least one non-whitespace character, so the url_view won't be empty. I've removed the check. Aaron --- gdb/debuginfod: Prevent out_of_range exception Trailing whitespace in the string of debuginfod URLs causes an out_of_range exception during the printing of URLs for the first use notice. To fix this, stop printing URLs when the substring to be printed consists only of whitespace. Also add first-use notice testcases. --- gdb/debuginfod-support.c | 7 +- .../gdb.debuginfod/fetch_src_and_symbols.exp | 67 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 6c2d3fb2951..4ce2e786b6a 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -187,10 +187,11 @@ debuginfod_is_enabled () gdb::string_view url_view (urls); while (true) { - url_view = url_view.substr (url_view.find_first_not_of (' ')); - if (url_view.empty ()) + size_t off = url_view.find_first_not_of (' '); + if (off == gdb::string_view::npos) break; - size_t off = url_view.find_first_of (' '); + url_view = url_view.substr (off); + off = url_view.find_first_of (' '); gdb_printf (_(" <%ps>\n"), styled_string (file_name_style.style (), diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp index f12ed7d486c..3eb27276538 100644 --- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp +++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp @@ -279,6 +279,73 @@ proc local_url { } { gdb_test_no_output "set debuginfod enabled on" gdb_test "file $binfile" ".*Reading symbols from.*debuginfo.*" \ "file [file tail $binfile] cmd on" + + global gdb_prompt + + # Test that URLs are printed correctly for the first-use notice + set testname "Notice empty URL" + set url "" + setenv DEBUGINFOD_URLS $url + clean_restart + send_gdb "file $binfile\n" + gdb_expect { + -re ".*Enable debuginfod.*" { fail $testname } + -re ".*$gdb_prompt" { pass $testname } + timeout { fail $testname } + } + + set testname "Notice whitespace URL" + set url " " + setenv DEBUGINFOD_URLS $url + clean_restart + send_gdb "file $binfile\n" + gdb_expect { + -re ".*URLs:\r\nEnable debuginfod.*" { pass $testname } + -re ".*$gdb_prompt" { fail $testname } + timeout { fail $testname } + } + + set testname "Notice 1 URL" + set url "http://127.0.0.1:$port" + setenv DEBUGINFOD_URLS $url + clean_restart + send_gdb "file $binfile\n" + gdb_expect { + -re ".*<$url>.*" { pass $testname } + -re "$gdb_prompt" { fail $testname } + timeout { fail $testname } + } + + set testname "Notice 1 URL with whitespace" + setenv DEBUGINFOD_URLS " $url " + clean_restart + send_gdb "file $binfile\n" + gdb_expect { + -re ".*<$url>.*" { pass $testname } + -re "$gdb_prompt" { fail $testname } + timeout { fail $testname } + } + + set testname "Notice 2 URLs" + set url2 "127.0.0.1:$port" + setenv DEBUGINFOD_URLS "$url $url2" + clean_restart + send_gdb "file $binfile\n" + gdb_expect { + -re ".*<$url>\r\n.*<$url2>.*" { pass $testname } + -re "$gdb_prompt" { fail $testname } + timeout { fail $testname } + } + + set testname "Notice 2 URLs with whitespace" + setenv DEBUGINFOD_URLS " $url $url2 " + clean_restart + send_gdb "file $binfile\n" + gdb_expect { + -re ".*<$url>\r\n.*<$url2>.*" { pass $testname } + -re "$gdb_prompt" { fail $testname } + timeout { fail $testname } + } } set envlist \ -- 2.35.1