[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#804102: Undefined Behavior in .../include/c++/4.9/bits/ios_base.h



Package: libstdc++6
Source: gcc-4.9
Version: 4.9.2-10

**********

I believe the fix is to cast from an Ios_Fmtflags to an unsigned type,
perform the bit operations, and then cast back to a Ios_Fmtflags
before returning it.

I recall seeing this one in some Apple headers. Also see
http://lists.llvm.org/pipermail/cfe-dev/2015-January/040945.html .

**********

$ cat tt.cxx
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
  cout << std::hex << argc << std::dec << argc << endl;
  return 0;
}

$ clang++ -fsanitize=undefined tt.cxx -o tt.exe

$ ./tt.exe
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/ios_base.h:96:24:
runtime error: load of value 4294967221, which is not a valid value
for type 'std::_Ios_Fmtflags'
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/ios_base.h:76:67:
runtime error: load of value 4294967221, which is not a valid value
for type 'std::_Ios_Fmtflags'
...

**********

$ apt-cache show libstdc++
Package: libstdc++6
Source: gcc-4.9
Version: 4.9.2-10
Installed-Size: 1319
Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Architecture: amd64
Replaces: libstdc++6-4.9-dbg (<< 4.9.0-3)
Depends: gcc-4.9-base (= 4.9.2-10), libc6 (>= 2.18), libgcc1 (>= 1:4.1.1)
Pre-Depends: multiarch-support
Conflicts: scim (<< 1.4.2-1)
Breaks: gcc-4.3 (<< 4.3.6-1), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2)
Description-en: GNU Standard C++ Library v3
 This package contains an additional runtime library for C++ programs
 built with the GNU compiler.
 .
 libstdc++-v3 is a complete rewrite from the previous libstdc++-v2, which
 was included up to g++-2.95. The first version of libstdc++-v3 appeared
 in g++-3.0.
Description-md5: 724ab84919e0e220afb960e36463914d
Multi-Arch: same
Homepage: http://gcc.gnu.org/
Tag: implemented-in::c++, role::shared-lib
Section: libs
Priority: important
Filename: pool/main/g/gcc-4.9/libstdc++6_4.9.2-10_amd64.deb
Size: 272946
MD5sum: 391ae724457378c71fb16fb5d8eb232c
SHA1: 234c8593643d0e3bcfd36302f48edeaa4ca01fe5
SHA256: f1509bbabd78e89c861de16931aec5988e1215649688fd4f8dfe1af875a7fbef


Reply to: