security/sandbox/chromium/base/strings/string_util_stripped.cc

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 #include <wchar.h>
michael@0 2
michael@0 3 namespace base {
michael@0 4
michael@0 5 bool IsWprintfFormatPortable(const wchar_t* format) {
michael@0 6 for (const wchar_t* position = format; *position != '\0'; ++position) {
michael@0 7 if (*position == '%') {
michael@0 8 bool in_specification = true;
michael@0 9 bool modifier_l = false;
michael@0 10 while (in_specification) {
michael@0 11 // Eat up characters until reaching a known specifier.
michael@0 12 if (*++position == '\0') {
michael@0 13 // The format string ended in the middle of a specification. Call
michael@0 14 // it portable because no unportable specifications were found. The
michael@0 15 // string is equally broken on all platforms.
michael@0 16 return true;
michael@0 17 }
michael@0 18
michael@0 19 if (*position == 'l') {
michael@0 20 // 'l' is the only thing that can save the 's' and 'c' specifiers.
michael@0 21 modifier_l = true;
michael@0 22 } else if (((*position == 's' || *position == 'c') && !modifier_l) ||
michael@0 23 *position == 'S' || *position == 'C' || *position == 'F' ||
michael@0 24 *position == 'D' || *position == 'O' || *position == 'U') {
michael@0 25 // Not portable.
michael@0 26 return false;
michael@0 27 }
michael@0 28
michael@0 29 if (wcschr(L"diouxXeEfgGaAcspn%", *position)) {
michael@0 30 // Portable, keep scanning the rest of the format string.
michael@0 31 in_specification = false;
michael@0 32 }
michael@0 33 }
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 return true;
michael@0 38 }
michael@0 39
michael@0 40 } // namespace base
michael@0 41

mercurial