1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/strings/string_util_stripped.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,41 @@ 1.4 +#include <wchar.h> 1.5 + 1.6 +namespace base { 1.7 + 1.8 +bool IsWprintfFormatPortable(const wchar_t* format) { 1.9 + for (const wchar_t* position = format; *position != '\0'; ++position) { 1.10 + if (*position == '%') { 1.11 + bool in_specification = true; 1.12 + bool modifier_l = false; 1.13 + while (in_specification) { 1.14 + // Eat up characters until reaching a known specifier. 1.15 + if (*++position == '\0') { 1.16 + // The format string ended in the middle of a specification. Call 1.17 + // it portable because no unportable specifications were found. The 1.18 + // string is equally broken on all platforms. 1.19 + return true; 1.20 + } 1.21 + 1.22 + if (*position == 'l') { 1.23 + // 'l' is the only thing that can save the 's' and 'c' specifiers. 1.24 + modifier_l = true; 1.25 + } else if (((*position == 's' || *position == 'c') && !modifier_l) || 1.26 + *position == 'S' || *position == 'C' || *position == 'F' || 1.27 + *position == 'D' || *position == 'O' || *position == 'U') { 1.28 + // Not portable. 1.29 + return false; 1.30 + } 1.31 + 1.32 + if (wcschr(L"diouxXeEfgGaAcspn%", *position)) { 1.33 + // Portable, keep scanning the rest of the format string. 1.34 + in_specification = false; 1.35 + } 1.36 + } 1.37 + } 1.38 + } 1.39 + 1.40 + return true; 1.41 +} 1.42 + 1.43 +} // namespace base 1.44 +