New issue
Advanced search Search tips

Issue 758724 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Sep 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

crashpad.cc passes StringPiece to function expecting NUL-terminated const char*

Project Member Reported by brucedaw...@chromium.org, Aug 24 2017

Issue description

string_piece.h says:

  // data() may return a pointer to a buffer with embedded NULs, and the
  // returned buffer may or may not be null terminated.  Therefore it is
  // typically a mistake to pass data() to a routine that expects a NUL
  // terminated string.
  const value_type* data() const { return ptr_; }

This makes sense because a StringPiece may reference a substring of an existing string in which case NUL termination is impossible.

Meanwhile, in crashpad.cc we have:

void SetCrashKeyValue(const base::StringPiece& key,
                      const base::StringPiece& value) {
  // Convert from StringPiece to string to ensure null-termination.
  g_simple_string_dictionary->SetKeyValue(key.as_string().c_str(),
                                          value.as_string().c_str());
}

void ClearCrashKey(const base::StringPiece& key) {
  // Convert from StringPiece to string to ensure null-termination.
  g_simple_string_dictionary->RemoveKey(key.as_string().c_str());
}

Where the signatures of SetKeyValue and RemoveKey are:

SetKeyValue(const char* key, const char* value)
void RemoveKey(const char* key)


So, SetCrashKeyValue and ClearCrashKey value are violating the StringPiece contract. Prior to C++ 11 this could be a problem because std::string objects were not guaranteed to be NUL terminated, but with C++ 11 they are. So, probably the only risk is if SetCrashKeyValue or ClearCrashKey are called with sub-strings of some sort, and it appears that they are not.

On the other hand, converting from StringPiece to const char* is still generally a bad idea because the length information is lost and usually has to be reconstructed.

So, to avoid the risk of bugs and to allow for greater efficiency we should retain StringPiece all the way down. This should be kept in mind as the crash key system is redesigned, and I'll clean it up slightly for now.

 

Comment 1 by siggi@chromium.org, Sep 6 2017

Owner: siggi@chromium.org
Status: Started (was: Assigned)

Comment 2 by siggi@chromium.org, Sep 6 2017

Cc: brucedaw...@chromium.org
Components: Internals>CrashReporting
Labels: -Pri-3 Pri-2
Project Member

Comment 3 by bugdroid1@chromium.org, Sep 6 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/97fba6506881970e6c7b0578a9cee9ef977321fe

commit 97fba6506881970e6c7b0578a9cee9ef977321fe
Author: Sigurdur Asgeirsson <siggi@chromium.org>
Date: Wed Sep 06 18:47:02 2017

Update Crashpad to 20ed4146d37705a12a5b603a89c97f206f58d14c

f16e4eb9ffbf Implement SleepNanoseconds() on Windows
b953388b9553 Add SystemSnapshotLinux
ad1b86535c6a Roll mini_chromium to 068fe690218f
20ed4146d377 Use StringPiece for key and value in SimpleStringDictionary
             interface

Bug:  758724 
Change-Id: I0ef3d1a95dd2b2475a11256891beca32ab593fc5
Reviewed-on: https://chromium-review.googlesource.com/652669
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#500022}
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/build/secondary/third_party/crashpad/crashpad/snapshot/BUILD.gn
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/README.chromium
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/DEPS
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/build/gyp_crashpad_android.py
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/client/simple_string_dictionary.h
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/linux/system_snapshot_linux.cc
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/linux/system_snapshot_linux.h
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/linux/system_snapshot_linux_test.cc
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/mac/system_snapshot_mac.cc
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/mac/system_snapshot_mac_test.cc
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/posix/timezone.cc
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/posix/timezone.h
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/posix/timezone_test.cc
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/snapshot.gyp
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/snapshot_test.gyp
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/system_snapshot.h
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/x86/cpuid_reader.cc
[add] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/snapshot/x86/cpuid_reader.h
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/util/misc/clock.h
[modify] https://crrev.com/97fba6506881970e6c7b0578a9cee9ef977321fe/third_party/crashpad/crashpad/util/misc/clock_win.cc

Project Member

Comment 4 by bugdroid1@chromium.org, Sep 6 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/73304dfabbd84ffc510c6716dd8172c29698f320

commit 73304dfabbd84ffc510c6716dd8172c29698f320
Author: Sigurdur Asgeirsson <siggi@chromium.org>
Date: Wed Sep 06 20:13:07 2017

Pass crash key and value length through export thunks.

This uses the StringPiece interface to crash keys which appeared
in Crashpad 20ed4146d37705a12a5b603a89c97f206f58d14c. With this change,
it is safe to use non-NUL terminated StringPiece crash keys and values.

Bug:  758724 
Change-Id: I9c1630cdef9d5393dbb9eb50041eeb166f99a680
Reviewed-on: https://chromium-review.googlesource.com/652942
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: Brett Wilson <brettw@chromium.org>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#500059}
[modify] https://crrev.com/73304dfabbd84ffc510c6716dd8172c29698f320/chrome/common/child_process_logging_win.cc
[modify] https://crrev.com/73304dfabbd84ffc510c6716dd8172c29698f320/components/crash/content/app/crash_export_stubs.cc
[modify] https://crrev.com/73304dfabbd84ffc510c6716dd8172c29698f320/components/crash/content/app/crash_export_thunks.cc
[modify] https://crrev.com/73304dfabbd84ffc510c6716dd8172c29698f320/components/crash/content/app/crash_export_thunks.h
[modify] https://crrev.com/73304dfabbd84ffc510c6716dd8172c29698f320/components/crash/content/app/crashpad.cc

Comment 5 by siggi@chromium.org, Sep 7 2017

Status: Fixed (was: Started)

Sign in to add a comment