Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 |