Message ID | 20230503021713.1146069-2-tchaikov@gmail.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1026479vqo; Tue, 2 May 2023 19:19:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sDb8IOyQ9P9RFxmIrhycF6GlMv9jcVS8g5NYBk11A4QYNOWXOy0NlMZ3cgIehbD90lqFR X-Received: by 2002:aa7:de91:0:b0:504:7f60:9f6d with SMTP id j17-20020aa7de91000000b005047f609f6dmr9483156edv.9.1683080374632; Tue, 02 May 2023 19:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683080374; cv=none; d=google.com; s=arc-20160816; b=qKo0xshbZNrL75vGtm3nypTiW1Um6Dnn3tN1Fho7DCQGjmKBk495do4cqD/x+5/m7r GmWPPHsYc/2+x91oqFtsar08k3KDAQoFAwvK2shqVDf8rRTat/fpP9SL6I44W3dTNNY/ G0JtS/pibm05ugFMrjj9mfqSaB4viBnHXiRrHmYvQHhQTFNVm+6AXBCtWFqINaRrZwGK zgy9TGF5iDNf7j3OYDZcXvpB4QfBuvqqiedEiipBRZu00fjdYZkDFqkGJAvf6F2hu0/b GNvL0Z6/HzVYPOhhI1p3eGYALfZpmqbp/ePknC7Ty2lkqE0HKR09fyiwyggcHIm5L8VF BhuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=OCBxQQsS95YUO9tb6/CowBT9aH8PJGCsPyWoAgyQekQ=; b=kFX3votCHkEXAlMp85NVQAl8vFRSSdTW5P3gz24S+9y6X7rUzZ/RaoLGuxoYGKePND 4qmQoVj5v7m6v9OMl80D9BbZGxhoBvebPohZkB38q8r8cogvUQdkdv37KHKvrIA8MXAs KvawTCdywM1KthP8kjJ8Lnyaq0ckIEcL8fSYKSS5x9Um8Y6d706Vw0n8SFkQr4osx/oX AT5RywQUe7oXNc7EpGLp1KuEBI4+//XXLD4AQ9uqj7lP18zQnKgr77InmdIDYhM4+LtT w0epv1+pzEf4FUeqtQ+izw+a4LpTISY5Uk7Y9HY09q06fzSZb6QGe/x98EB+XTtlTyV7 fpmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nRJbyh9o; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w20-20020a056402071400b0050bc838b743si305002edx.173.2023.05.02.19.19.34 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 19:19:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nRJbyh9o; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68AB73857702 for <ouuuleilei@gmail.com>; Wed, 3 May 2023 02:18:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68AB73857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683080326; bh=OCBxQQsS95YUO9tb6/CowBT9aH8PJGCsPyWoAgyQekQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nRJbyh9oIsxXJHfgFxq6yJbcMJU7d24/6Qk/9rwNKkJN6fOm/5BRwoxf8dvTzhouj M3hQZ8PMflcfi6zDjbkviauN7W5eYtETmfXPnwiYJrBaZ6uQJLGmTVCC9V834vvCM3 4NRnld7TdWq2E/SBvi3Qz2EBhDvxR4/bcZLQiPZw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id E1F303858D20; Wed, 3 May 2023 02:17:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1F303858D20 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64115e652eeso1578228b3a.0; Tue, 02 May 2023 19:17:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683080247; x=1685672247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OCBxQQsS95YUO9tb6/CowBT9aH8PJGCsPyWoAgyQekQ=; b=EDXNtQgyIH3V6tzIov7gP6q+w4qszGnMYd2WobtcxlpKcpvD0kdHWTMJU1dR0dsI/0 I9jABqzkrLrU0o1HBjKKMYzOYFJl+32wcyFbyuScNNWzdBBQjfF0BJYMV81FmcK+gQZG zFWntpVkl26DqgZ9M16FgG4fa1BMOgoKGGQ+S/xWOVf0uo0oadIkPtGK3aj7tAbSO93o EQBFN8PJNdWBYnauiqj5FZLuBsyqvJyXYjQfLHmjS48DLnjc9BA643z3Ft3DHOGinJQe xfglCyGd1WrOnj+mcxAb0es9VsLGBqbeY6Tkp+JJQabThrnarGM5+rFxzrM1z8Sxf0Nu J8tQ== X-Gm-Message-State: AC+VfDxHADXu/pIGIp7NM9Oe7o6HnQ/q8q7YH2Wq+aF2QuXhm49HIJng YciAZBsu6XEskeDqPetnuPU5P6GB12vmgg== X-Received: by 2002:a05:6a00:2d25:b0:62d:bf69:e9e0 with SMTP id fa37-20020a056a002d2500b0062dbf69e9e0mr725357pfb.17.1683080247546; Tue, 02 May 2023 19:17:27 -0700 (PDT) Received: from localhost.localdomain ([101.93.160.94]) by smtp.gmail.com with ESMTPSA id a15-20020a056a000c8f00b0063b8ddf77f7sm22452912pfv.211.2023.05.02.19.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 19:17:27 -0700 (PDT) To: libstdc++@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org, Kefu Chai <tchaikov@gmail.com>, Kefu Chai <kefu.chai@scylladb.com>, Jonathan Wakely <jwakely@redhat.com> Subject: [PATCH v2 1/1] libstdc++: Set _M_string_length before calling _M_dispose() [PR109703] Date: Wed, 3 May 2023 10:17:13 +0800 Message-Id: <20230503021713.1146069-2-tchaikov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230503021713.1146069-1-tchaikov@gmail.com> References: <20230501070622.847749-2-tchaikov@gmail.com> <20230503021713.1146069-1-tchaikov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Kefu Chai via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Kefu Chai <tchaikov@gmail.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764837686785671086?= X-GMAIL-MSGID: =?utf-8?q?1764837686785671086?= |
Series |
Set _M_string_length before calling _M_dispose()
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
kefu chai
May 3, 2023, 2:17 a.m. UTC
This patch always sets _M_string_length in the constructor specialized
for range of input_iterator, for the cases like istringstream.
We copy from source range to the local buffer, and then reallocate to
a larger one if necessary. When disposing the old buffer, the old buffer
could be provisioned by the local buffer or an allocated buffer.
_M_is_local() is used to tell if the buffer is the local one or not. In
addition to comparing the buffer address with the local buffer, this
function also performs the sanity checking if _M_string_length is greater
than _S_local_capacity, if the check fails __builtin_unreachable() is
called. But we failed to set _M_string_length in this constructor is
specialized for std::input_iterator. So, if UBSan is enabled when
compiling the source, there are chances that the uninitialized data in
_M_string_length is greater than _S_local_capacity, and the application
aborts a runtime error or exception emitted by the UBSan.
In this change, to avoid the false alarm, _M_string_length is
initialized to zero before doing anything else, so that _M_is_local()
doesn't see an uninitialized value.
This issue only surfaces when constructing a string with a range of
input_iterator, and the uninitialized _M_string_length is greater than
_S_local_capacity, i.e., 15.
libstdc++-v3/ChangeLog:
PR libstdc++/109703
* include/bits/basic_string.h (basic_string(Iter, Iter, Alloc)):
Initialize _M_string_length.
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
---
libstdc++-v3/include/bits/basic_string.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 8247ee6bdc6..b16b2898b62 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -760,7 +760,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _GLIBCXX20_CONSTEXPR basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a = _Alloc()) - : _M_dataplus(_M_local_data(), __a) + : _M_dataplus(_M_local_data(), __a), _M_string_length(0) { #if __cplusplus >= 201103L _M_construct(__beg, __end, std::__iterator_category(__beg));