Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Issue 1283243004: ubsan: Don’t call v[0] on empty vectors (Closed)

Created:
5 years, 4 months ago by Mark Mentovai
Modified:
5 years, 4 months ago
Reviewers:
Robert Sesek
CC:
crashpad-dev_chromium.org
Base URL:
https://chromium.googlesource.com/crashpad/crashpad@master
Target Ref:
refs/heads/master
Project:
crashpad
Visibility:
Public.

Description

ubsan: Don’t call v[0] on empty vectors Calling std::vector<>::operator[]() with an out-of-range index argument is undefined behavior. In two cases, Crashpad used &v[0] in situations where it was known that the address would not be used. These calls were wrapped in conditions guarding against vector emptiness. While s[0] is valid on an empty string, in two cases, Crashpad used &s[0] as an argument to a system call that would be a no-op. These calls were wrapped in similar conditions to avoid the system call. The two uses of vector with undefined behavior were caught by the following tests in crashpad_snapshot_test with UndefinedBehaviorSanitizer: [ RUN ] CrashpadInfoClientOptions.OneModule /Users/mark/compilatorium/llvm.build/bin/../include/c++/v1/vector:1493:12: runtime error: reference binding to null pointer of type 'crashpad::process_types::section' [ OK ] CrashpadInfoClientOptions.OneModule (72 ms) [ RUN ] ProcessSnapshotMinidump.Empty /Users/mark/compilatorium/llvm.build/bin/../include/c++/v1/vector:1493:12: runtime error: reference binding to null pointer of type 'MINIDUMP_DIRECTORY' [ OK ] ProcessSnapshotMinidump.Empty (1 ms) The Crashpad codebase was audited by searching for resize() calls and analyzing how resized strings and vectors are used. TEST=* BUG= R=rsesek@chromium.org Committed: https://chromium.googlesource.com/crashpad/crashpad/+/34aef02cc725795de2882e3ea30b048568048e12

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+15 lines, -11 lines) Patch
M snapshot/mac/mach_o_image_segment_reader.cc View 1 chunk +2 lines, -1 line 0 comments Download
M snapshot/minidump/process_snapshot_minidump.cc View 1 chunk +2 lines, -1 line 0 comments Download
M util/mac/xattr.cc View 1 chunk +9 lines, -7 lines 0 comments Download
M util/mach/child_port_handshake.cc View 1 chunk +2 lines, -2 lines 0 comments Download

Messages

Total messages: 5 (1 generated)
Mark Mentovai
5 years, 4 months ago (2015-08-20 15:14:15 UTC) #2
Robert Sesek
LGTM. Also, the CL description says "std::vector::operator<>() " -- should probably be "std::vector<>::operator[]()"
5 years, 4 months ago (2015-08-20 15:16:31 UTC) #3
Mark Mentovai
Thanks, fixed the description.
5 years, 4 months ago (2015-08-20 15:50:09 UTC) #4
Mark Mentovai
5 years, 4 months ago (2015-08-20 15:50:30 UTC) #5
Message was sent while issue was closed.
Committed patchset #1 (id:1) manually as
34aef02cc725795de2882e3ea30b048568048e12 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698