From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52474 invoked by alias); 6 Mar 2015 12:31:58 -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 52448 invoked by uid 89); 6 Mar 2015 12:31:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 06 Mar 2015 12:31:56 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t26CVsf4030636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 6 Mar 2015 07:31:54 -0500 Received: from localhost (ovpn-116-114.ams2.redhat.com [10.36.116.114]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t26CVrat001076; Fri, 6 Mar 2015 07:31:53 -0500 Date: Fri, 06 Mar 2015 12:31:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] Fix dangling pointer in future_error::what() Message-ID: <20150306123153.GL8789@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="KJY2Ze80yH5MUxol" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-03/txt/msg00359.txt.bz2 --KJY2Ze80yH5MUxol Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 251 This bug didn't show up with COW strings, but is a real problem with the new std::string. The fix is to call error_code::message() early and store the result in the logic_error base class during construction. Tested x86_64-linux, committed to trunk. --KJY2Ze80yH5MUxol Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 1373 commit 3f7252dcc10eba698c12460c0a74bd313c7fef01 Author: Jonathan Wakely Date: Fri Mar 6 11:04:13 2015 +0000 * include/std/future (future_error(error_code)): Construct base class with error_code's message. * src/c++11/future.cc (future_error::what()): Do not call c_str() on temporary string. diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index cb0226d..fc3f816 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -98,7 +98,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: explicit future_error(error_code __ec) - : logic_error("std::future_error"), _M_code(__ec) + : logic_error("std::future_error: " + __ec.message()), _M_code(__ec) { } virtual ~future_error() noexcept; diff --git a/libstdc++-v3/src/c++11/future.cc b/libstdc++-v3/src/c++11/future.cc index c711a5f..3cf503b 100644 --- a/libstdc++-v3/src/c++11/future.cc +++ b/libstdc++-v3/src/c++11/future.cc @@ -75,7 +75,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION future_error::~future_error() noexcept { } const char* - future_error::what() const noexcept { return _M_code.message().c_str(); } + future_error::what() const noexcept { return logic_error::what(); } #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ && (ATOMIC_INT_LOCK_FREE > 1) --KJY2Ze80yH5MUxol--