From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71422 invoked by alias); 1 Oct 2019 18:23:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 71414 invoked by uid 89); 1 Oct 2019 18:23:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=supposedly, living X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Oct 2019 18:23:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1569954231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D5xHn5y+EgjPlX6pa+l5e331QMd5SpVna8Fz0e0S1Ao=; b=JQ5/EFRtqN4uPEYvkzdm8ka04HYP5PKR0L64er4F6GGyEA1T+g6LVDoVAudYyBm2pSJhZK xVw6s6jupmg5EwFoe38D8GumdZVXP/dnRyFIxjk9TmO1SqftRDuPhJpOS3tq87q1mF+bzx gB5fRZsjrMET2VqxmDS9o/efWt4xJTk= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-Hp07KR_kNK6gaZIdapRzPw-1; Tue, 01 Oct 2019 14:23:45 -0400 Received: by mail-wm1-f70.google.com with SMTP id 124so1102899wmz.1 for ; Tue, 01 Oct 2019 11:23:45 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id i14sm16268560wra.78.2019.10.01.11.23.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2019 11:23:43 -0700 (PDT) Subject: Re: [PATCH] Change some arguments to gdb::string_view instead of name+len To: Christian Biesinger , gdb-patches@sourceware.org References: <20191001173345.48753-1-cbiesinger@google.com> From: Pedro Alves Message-ID: Date: Tue, 01 Oct 2019 18:23:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20191001173345.48753-1-cbiesinger@google.com> X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2019-10/txt/msg00028.txt.bz2 On 10/1/19 6:33 PM, Christian Biesinger via gdb-patches wrote: > - if (linkage_name[len] !=3D '\0') > + /* Don't use string_view::operator[] because we are accessing beyond > + the size of the string_view, which is technically unsupported. */ > + if (linkage_name.data ()[linkage_name.length ()] !=3D '\0') > { > char *alloc_name; It's more than just unsupported, it's undefined behavior. If we're promisi= ng the string_view interface, then it's supposedly valid to pass in a string_v= iew that happens to point just at the end of a page, with the one-past-the-end byte living in an unmapped page. Dereferencing the one-past-end byte in that case SIGSEGVs. > - if (ms_type =3D=3D mst_file_text && startswith (name, "__gnu_compiled"= )) > + if (ms_type =3D=3D mst_file_text && startswith (name.data (), "__gnu_c= ompiled")) > return (NULL); >=20=20 This, via startswith also assumes that name.data() is a null-terminated string. I wonder whether we should have a zstring_view type. like string_view, but assumes/requires null-terminated. Thanks, Pedro Alves