From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7928 invoked by alias); 23 Feb 2019 01:06:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 7912 invoked by uid 89); 23 Feb 2019 01:06:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 23 Feb 2019 01:06:17 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C517FA779; Sat, 23 Feb 2019 01:06:15 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-64.ams2.redhat.com [10.36.117.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E31260C80; Sat, 23 Feb 2019 01:06:15 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x1N16CCU011237; Sat, 23 Feb 2019 02:06:13 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x1N16BtU011236; Sat, 23 Feb 2019 02:06:11 +0100 Date: Sat, 23 Feb 2019 01:27:00 -0000 From: Jakub Jelinek To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] PR libstdc++/89446 fix null pointer dereference in char_traits Message-ID: <20190223010611.GN7611@tucnak> Reply-To: Jakub Jelinek References: <20190223010220.GA32714@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190223010220.GA32714@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes X-SW-Source: 2019-02/txt/msg01872.txt.bz2 On Sat, Feb 23, 2019 at 01:02:20AM +0000, Jonathan Wakely wrote: > PR libstdc++/89446 > * include/bits/char_traits.h (__constant_char_array): Check index is > in range before dereferencing. > * testsuite/21_strings/basic_string_view/operators/char/89446.cc: > New test. > > Tested x86_64-linux, committed to gcc-8-branch and gcc-7-branch. And not trunk? The bug is still there, even when it should be usually ifdefed out because __builtin_is_constexpr_evaluated() should be supported. > commit b639a9cac6e2532eb852b03df6ac40d34f1dd28c > Author: Jonathan Wakely > Date: Fri Feb 22 20:33:16 2019 +0000 > > PR libstdc++/89446 fix null pointer dereference in char_traits > > PR libstdc++/89446 > * include/bits/char_traits.h (__constant_char_array): Check index is > in range before dereferencing. > * testsuite/21_strings/basic_string_view/operators/char/89446.cc: > New test. > > diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h > index 1945494d7e2..a2a883f3565 100644 > --- a/libstdc++-v3/include/bits/char_traits.h > +++ b/libstdc++-v3/include/bits/char_traits.h > @@ -248,7 +248,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > __constant_char_array_p(const _CharT* __a, size_t __n) > { > size_t __i = 0; > - while (__builtin_constant_p(__a[__i]) && __i < __n) > + while (__i < __n && __builtin_constant_p(__a[__i])) > __i++; > return __i == __n; > } Jakub