[LLVMbugs] [Bug 18403] New: Sigsegv in exception::what() after r

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jan 6 12:53:30 PST 2014


            Bug ID: 18403
           Summary: Sigsegv in exception::what() after r
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: jonathan.sauer at gmx.de
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following program, when compiled with clang r198596 and libc++ r198635
(which was also compiled with clang r198596), crashes with a SIGSEGV when run:

#include <cstdio>
#include <stdexcept>

int main()
        throw std::runtime_error("Error");
    catch (const std::exception& e)
        std::printf("%s\n", e.what());

This results in:

% ~/LLVM/build/Release+Asserts/bin/clang++ -std=c++11 -stdlib=libc++ clang.cpp
% gdb ./a.out
(gdb) r
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x00000001000425e6 in std::runtime_error::what ()
(gdb) bt
#0  0x00000001000425e6 in std::runtime_error::what ()
#1  0x0000000100000da3 in main ()

After reverting to r198504 (before the last change to stdexcept.cpp), the code
ran fine.

I suspect the cause of the crash lies in the following change in

 runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT
-    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
-    ::new(&s) __libcpp_nmstr((const __libcpp_nmstr&)le.__imp_);
+    __libcpp_nmstr *s = static_cast<__libcpp_nmstr *>(__imp_);
+    const __libcpp_nmstr *s2 = static_cast<const __libcpp_nmstr *>(le.__imp_);
+    ::new(s) __libcpp_nmstr(*s2);

Before the new "__libcpp_nmstr" was created inside "__imp_" (as "s" was a
reference to it, and taking the address of a reference means taking the address
of the referenced variable, i.e. "__imp_"). Now the new string is created
inside "s" and never gets stored in "__imp_".

Proposed fix: Remove "s" and just say:

  ::new(__imp_) __libcpp_nmstr(*s2);

(same in the other constructors as well)


You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140106/b3bc59fb/attachment.html>

More information about the llvm-bugs mailing list