Bug 1591823 - c++17 data() member function of std::string undesired side effects
Summary: c++17 data() member function of std::string undesired side effects
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Developer Toolset
Classification: Red Hat
Component: gcc
Version: DTS 7.1 RHEL 7
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: alpha
: 7.1
Assignee: Marek Polacek
QA Contact: Michael Petlan
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-06-15 16:12 UTC by Hubert Krause
Modified: 2018-11-13 08:39 UTC (History)
8 users (show)

Fixed In Version: devtoolset-8-gcc-8.1.1-5.el7
Doc Type: Bug Fix
Doc Text:
Previously, the non-const basic_string::data() overload in the standard C++ library was failing to unshare the string, which could lead to inadvertent modification of the string, resulting in misbehavior of the program.
Clone Of:
Environment:
Last Closed: 2018-11-13 08:38:30 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
c++ file to reproduce the problem (1.55 KB, text/x-csrc)
2018-06-15 16:12 UTC, Hubert Krause
no flags Details


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 86169 0 P3 RESOLVED .data() fails to unshare strings 2021-01-20 16:05:33 UTC
Red Hat Product Errata RHBA-2018:3562 0 None None None 2018-11-13 08:39:11 UTC

Description Hubert Krause 2018-06-15 16:12:40 UTC
Created attachment 1451986 [details]
c++ file to reproduce the problem

Description of problem:


Version-Release number of selected component (if applicable):

gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)


How reproducible:

always, easy

Steps to Reproduce:
1. g++ -std=c++17 a.cpp
2. ./a.out
3.

Actual results:

BEFORE
s0 = hello world
s1 = hello world
s2 = hello world
AFTER modifying s1
s0 =  ello world   expecting = hello world
s1 =  ello world   expecting =  ello world
s2 =  ello world   expecting = hello world

Expected results:

BEFORE
s0 = hello world
s1 = hello world
s2 = hello world
AFTER modifying s1
s0 = hello world   expecting = hello world
s1 =  ello world   expecting =  ello world
s2 = hello world   expecting = hello world

Additional info:

Comment 2 Hubert Krause 2018-06-18 08:29:12 UTC
Hello,

as an additional hint: this bug does not happen with gcc7.3.0 on Ubuntu 18.04 (version gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0)

Best regards,

Hubert Krause

Comment 3 Jonathan Wakely 2018-06-18 11:07:42 UTC
That's only because Ubuntu's GCC defaults to -D_GLIBCXX_USE_CXX11_ABI=1 and RHEL DTS defaults to -D_GLIBCXX_USE_CXX11_ABI=0

The exact same bug is present in Ubuntu.

It's now been fixed upstream.

Comment 4 Marek Polacek 2018-07-13 18:12:15 UTC
Fixed in DTS 8:
# g++ d.cc -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=1; ./a.out
# g++ d.cc -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=0; ./a.out

Comment 6 Michael Petlan 2018-11-06 19:42:05 UTC
VERIFIED for devtoolset-8-gcc-8.2.1-3.

Comment 8 errata-xmlrpc 2018-11-13 08:38:30 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:3562


Note You need to log in before you can comment on or make changes to this bug.