[llvm-bugs] [Bug 48912] New: stream sentry leaks exceptions
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jan 27 15:53:14 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=48912
Bug ID: 48912
Summary: stream sentry leaks exceptions
Product: libc++
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: lavr at ncbi.nlm.nih.gov
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
Created attachment 24429
--> https://bugs.llvm.org/attachment.cgi?id=24429&action=edit
test case
Since basic_[io]stream::sentry gets constructed outside the try/catch blocks in
most (if not all) I/O methods, and, in case of istream::sentry, does not have a
try/catch block on its own (in the ctor), it lets the lower-level exceptions
leak to the user code.
Consider an istream doing a string input, with "is >> str".
If white space is skipped (as it usually is the case), then there's some I/O
occurring within the sentry ctor. If that I/O (stream buffer operation) causes
the streambuf to throw, the exception is not caught, as it should at the
"operator>>" level, but gets leaked out. Also, "badbit" is not set (as the
standard mandates), and the stream data integrity is, thus, compromised.
This bug is both in versions 10 and 11 of libc++.
Attached is the simple code that demonstrates the issue.
When built with clang++, it produces:
> clang++ test.cpp
> ./a.out
caught
0
which basically shows there was an exception and the stream is in "good" state.
When built with a standard-conforming implementation, the output is this:
> ./a.out
5
Note: 5 = 1(badbit) + 4(failbit). That is the correct behavior of this
extraction operation.
--
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/20210127/e0b57c64/attachment-0001.html>
More information about the llvm-bugs
mailing list