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

Issue 18656004: Added a new SafeSPrintf() function that implements snprintf() in an async-safe-fashion (Closed)

Created:
7 years, 5 months ago by Markus (顧孟勤)
Modified:
7 years, 3 months ago
CC:
chromium-reviews, agl, jln+watch_chromium.org
Visibility:
Public.

Description

Added a new base::strings::SafeSPrintf() function that can safely be called from all restricted (e.g. async-signal-safe) environments. It is roughly equivalent to snprintf(). But it is easier to use, as it uses C++ to be type-safe. In release builds, this function is guaranteed to never call any other library function nor any system calls. In debug builds, we call RAW_CHECK() in some circumstances. This code is needed for (at least) the seccomp sandbox and to clean up code in the stack tracer. Those changes are pending and will be submitted as separate CLs. BUG=none TEST=base_unittests Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=220746

Patch Set 1 #

Patch Set 2 : Variadic templates make the code even cleaner (for C++-11) #

Patch Set 3 : Clean up DieFormatHelper() and fold SANDBOX_XXX_FORMATTED() into SANDBOX_XXX() #

Patch Set 4 : After the last refactoring, we can actually move the helper back into the outer "Die" class. #

Patch Set 5 : Moved into base/debug/format.*; added missing features needed by stack tracer; added unittest #

Patch Set 6 : Fixed reference value in unittest #

Total comments: 13

Patch Set 7 : Addressed Jeffrey's comments #

Total comments: 15

Patch Set 8 : Refactored to include just the new Format() function, but none of its users #

Patch Set 9 : Addressed Julien's comments #

Total comments: 9

Patch Set 10 : Refactored buffer management to address the first part of jln's comments and allow him to add more … #

Patch Set 11 : Added missing test, more clean ups requested by jln, more comments, support for octals #

Total comments: 53

Patch Set 12 : Addressed jln's comments #

Total comments: 3

Patch Set 13 : Disabled death tests on Android and added myself to OWNERS #

Patch Set 14 : Addressed jln's remaining comments #

Patch Set 15 : Moved to base/strings/ and renamed to SafeSPrintf() #

Total comments: 20

Patch Set 16 : Addressed Will's comments; renamed files to base/strings/safe_sprintf.* #

Total comments: 10

Patch Set 17 : Renamed some identifiers (prompted by rvargas' comments) #

Patch Set 18 : Refined comments at the top of safe_sprintf.h #

Total comments: 2

Patch Set 19 : Minor nits #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1887 lines, -0 lines) Patch
M base/base.gyp View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 chunk +1 line, -0 lines 0 comments Download
M base/base.gypi View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 chunk +2 lines, -0 lines 0 comments Download
A base/strings/OWNERS View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +1 line, -0 lines 0 comments Download
A base/strings/safe_sprintf.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 chunk +439 lines, -0 lines 0 comments Download
A base/strings/safe_sprintf.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 chunk +681 lines, -0 lines 0 comments Download
A base/strings/safe_sprintf_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 chunk +763 lines, -0 lines 0 comments Download

Messages

Total messages: 34 (0 generated)
Markus (顧孟勤)
Julien, this CL actually turned out to be more complicated than I originally anticipated. It ...
7 years, 5 months ago (2013-07-13 09:32:35 UTC) #1
jln (very slow on Chromium)
On 2013/07/13 09:32:35, Markus (顧孟勤) wrote: > Julien, this CL actually turned out to be ...
7 years, 5 months ago (2013-07-23 22:45:40 UTC) #2
Markus (顧孟勤)
I ended up moving the snprintf() implementation into base::debug::Format(). I then noticed that stacktrace_posix.cc had ...
7 years, 4 months ago (2013-07-29 08:22:18 UTC) #3
Markus (顧孟勤)
I added Jeffrey as a reviewer for C++ issues. Feel free to review more if ...
7 years, 4 months ago (2013-07-30 21:06:45 UTC) #4
Jeffrey Yasskin
The C++ side lgtm. https://codereview.chromium.org/18656004/diff/69001/base/debug/format.cc File base/debug/format.cc (right): https://codereview.chromium.org/18656004/diff/69001/base/debug/format.cc#newcode38 base/debug/format.cc:38: if (*count > std::numeric_limits<ssize_t>::max() - ...
7 years, 4 months ago (2013-07-30 23:13:53 UTC) #5
jln (very slow on Chromium)
Thanks for taking on this daunting task, async-signal safety is always regressing and a safe ...
7 years, 4 months ago (2013-08-01 00:03:14 UTC) #6
jln (very slow on Chromium)
Sending a new batch of remarks. Please, be extremely precise with the input and output ...
7 years, 4 months ago (2013-08-06 22:47:43 UTC) #7
Markus (顧孟勤)
I know I haven't addressed all of your comments just yet. But the refactoring should ...
7 years, 4 months ago (2013-08-09 01:49:25 UTC) #8
Markus (顧孟勤)
PTAL I think I now addressed all your initial comments, added the missing unittest, and ...
7 years, 4 months ago (2013-08-09 21:33:34 UTC) #9
jln (very slow on Chromium)
Sending the comments halfway through, so that you can start while I finish the review. ...
7 years, 4 months ago (2013-08-12 22:20:50 UTC) #10
jln (very slow on Chromium)
https://chromiumcodereview.appspot.com/18656004/diff/157001/base/debug/format.cc File base/debug/format.cc (right): https://chromiumcodereview.appspot.com/18656004/diff/157001/base/debug/format.cc#newcode233 base/debug/format.cc:233: // Return the current insertion point into the buffer. ...
7 years, 4 months ago (2013-08-12 22:49:40 UTC) #11
jln (very slow on Chromium)
https://chromiumcodereview.appspot.com/18656004/diff/157001/base/debug/format.cc File base/debug/format.cc (right): https://chromiumcodereview.appspot.com/18656004/diff/157001/base/debug/format.cc#newcode9 base/debug/format.cc:9: #include "base/debug/format.h" Please, have this as the first include ...
7 years, 4 months ago (2013-08-12 23:03:40 UTC) #12
Markus (顧孟勤)
I don't have time to go through all the comments one-by-one right now. But I ...
7 years, 4 months ago (2013-08-13 05:17:26 UTC) #13
Markus (顧孟勤)
https://codereview.chromium.org/18656004/diff/157001/base/debug/format.cc File base/debug/format.cc (right): https://codereview.chromium.org/18656004/diff/157001/base/debug/format.cc#newcode9 base/debug/format.cc:9: #include "base/debug/format.h" On 2013/08/12 23:03:40, Julien Tinnes wrote: > ...
7 years, 4 months ago (2013-08-13 16:13:18 UTC) #14
jln (very slow on Chromium)
Sorry, I've still not gotten to it. I'll take a look tomorrow!
7 years, 4 months ago (2013-08-14 01:19:29 UTC) #15
jln (very slow on Chromium)
lgtm with a few remaining nits to address. I think this is ready for owners ...
7 years, 4 months ago (2013-08-14 04:18:06 UTC) #16
Markus (顧孟勤)
Will, This is a type-safe and -- more importantly -- async-signal-safe implementation of snprintf(). We ...
7 years, 4 months ago (2013-08-14 07:17:33 UTC) #17
willchan no longer on Chromium
I'm favorably inclined to this changelist. I need to examine the API in detail, and ...
7 years, 4 months ago (2013-08-14 17:19:48 UTC) #18
Markus (顧孟勤)
I think this really depends on what we expect our long-term approach is going to ...
7 years, 4 months ago (2013-08-14 18:35:23 UTC) #19
jln (very slow on Chromium)
On 2013/08/14 18:35:23, Markus (顧孟勤) wrote: > I think this really depends on what we ...
7 years, 4 months ago (2013-08-14 18:54:23 UTC) #20
Markus (顧孟勤)
I moved and renamed the classes. Let me know, if this makes more sense. I ...
7 years, 4 months ago (2013-08-15 00:43:43 UTC) #21
willchan no longer on Chromium
I didn't have time to review everything, but I did a first pass. I suspect ...
7 years, 4 months ago (2013-08-15 07:36:17 UTC) #22
willchan no longer on Chromium
I didn't have time to review everything, but I did a first pass. I suspect ...
7 years, 4 months ago (2013-08-15 07:36:43 UTC) #23
Markus (顧孟勤)
I think I addressed all your comments, but please let me know, if there is ...
7 years, 4 months ago (2013-08-15 08:20:46 UTC) #24
rvargas (doing something else)
drive by. https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h File base/strings/safe_sprintf.h (right): https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h#newcode32 base/strings/safe_sprintf.h:32: // SafeSPrintf() is a type-safe and async-signal-safe ...
7 years, 4 months ago (2013-08-15 19:57:57 UTC) #25
Markus (顧孟勤)
Drive-by code reviews are always appreciated :-) https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h File base/strings/safe_sprintf.h (right): https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h#newcode32 base/strings/safe_sprintf.h:32: // SafeSPrintf() ...
7 years, 4 months ago (2013-08-15 20:31:20 UTC) #26
rvargas (doing something else)
thanks https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h File base/strings/safe_sprintf.h (right): https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h#newcode32 base/strings/safe_sprintf.h:32: // SafeSPrintf() is a type-safe and async-signal-safe version ...
7 years, 4 months ago (2013-08-15 21:38:47 UTC) #27
Markus (顧孟勤)
https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h File base/strings/safe_sprintf.h (right): https://codereview.chromium.org/18656004/diff/184002/base/strings/safe_sprintf.h#newcode32 base/strings/safe_sprintf.h:32: // SafeSPrintf() is a type-safe and async-signal-safe version of ...
7 years, 4 months ago (2013-08-15 21:46:53 UTC) #28
Markus (顧孟勤)
Will, just a quick reminder. I still need an LGTM from you (but I am ...
7 years, 3 months ago (2013-08-30 03:31:41 UTC) #29
willchan no longer on Chromium
My bad. I lost track of this CL. I'll try to remember to do it ...
7 years, 3 months ago (2013-08-30 16:27:54 UTC) #30
jln (very slow on Chromium)
On 2013/08/30 16:27:54, willchan wrote: > My bad. I lost track of this CL. I'll ...
7 years, 3 months ago (2013-08-30 23:02:52 UTC) #31
willchan no longer on Chromium
LGTM, I only skimmed the .cc file. I trust that jln/jyasskin reviewed that in detail. ...
7 years, 3 months ago (2013-08-30 23:17:07 UTC) #32
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/markus@chromium.org/18656004/261001
7 years, 3 months ago (2013-08-31 19:08:18 UTC) #33
commit-bot: I haz the power
7 years, 3 months ago (2013-09-01 22:53:15 UTC) #34
Message was sent while issue was closed.
Change committed as 220746

Powered by Google App Engine
This is Rietveld 408576698