Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/shared/Utils.cpp

Issue 5792731695677440: Fix named pipe security on Windows 7 (Closed)
Patch Set: Refactor to eliminate the corrupt ACL bug. Address comments. Created July 2, 2014, 9:47 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« src/shared/Communication.cpp ('K') | « src/shared/Communication.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <memory> 1 #include <memory>
2 #include <stdexcept> 2 #include <stdexcept>
3 #include <vector> 3 #include <vector>
4 4
5 #include <Windows.h> 5 #include <Windows.h>
6 #include <ShlObj.h> 6 #include <ShlObj.h>
7 7
8 #include "Utils.h" 8 #include "Utils.h"
9 9
10 namespace 10 namespace
11 { 11 {
12 // See http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx 12 // See http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx
13 EXTERN_C IMAGE_DOS_HEADER __ImageBase; 13 EXTERN_C IMAGE_DOS_HEADER __ImageBase;
14 14
15 std::wstring appDataPath; 15 std::wstring appDataPath;
16 16
17 } 17 }
18 18
19 std::unique_ptr<OSVERSIONINFOEX> GetWindowsVersion()
Felix Dahlke 2014/07/03 13:38:07 This seems like a refactoring, can we put it in a
Oleksandr 2014/07/03 13:51:49 It's addressing comments in this review. Shall we
Felix Dahlke 2014/07/03 13:56:33 Which comment? To switch to std::unique_ptr? That
Oleksandr 2014/07/03 14:00:42 http://codereview.adblockplus.org/5792731695677440
20 {
21 std::unique_ptr<OSVERSIONINFOEX> osvi(new OSVERSIONINFOEX());
22 osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
23 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(osvi.get()));
24 return osvi;
25 }
26
19 bool IsWindowsVistaOrLater() 27 bool IsWindowsVistaOrLater()
20 { 28 {
21 OSVERSIONINFOEX osvi; 29 std::unique_ptr<OSVERSIONINFOEX> osvi = GetWindowsVersion();
22 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 30 return osvi->dwMajorVersion >= 6;
23 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
24 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi));
25 return osvi.dwMajorVersion >= 6;
26 } 31 }
27 32
28 bool IsWindows8OrLater() 33 bool IsWindows8OrLater()
29 { 34 {
30 OSVERSIONINFOEX osvi; 35 std::unique_ptr<OSVERSIONINFOEX> osvi = GetWindowsVersion();
31 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 36 return (osvi->dwMajorVersion == 6 && osvi->dwMinorVersion >= 2) || osvi->dwMaj orVersion > 6;
32 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
33 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi));
34 return osvi.dwMajorVersion >= 6 && osvi.dwMinorVersion >= 2;
35 } 37 }
36 38
37 std::string ToUtf8String(const std::wstring& str) 39 std::string ToUtf8String(const std::wstring& str)
38 { 40 {
39 int length = static_cast<int>(str.size()); 41 int length = static_cast<int>(str.size());
40 if (length == 0) 42 if (length == 0)
41 return std::string(); 43 return std::string();
42 44
43 int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0); 45 int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0);
44 if (utf8StringLength == 0) 46 if (utf8StringLength == 0)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 123 }
122 124
123 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement) 125 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement)
124 { 126 {
125 size_t replaceStart = input.find(placeholder); 127 size_t replaceStart = input.find(placeholder);
126 if (replaceStart != std::string::npos) 128 if (replaceStart != std::string::npos)
127 { 129 {
128 input.replace(replaceStart, placeholder.length(), replacement); 130 input.replace(replaceStart, placeholder.length(), replacement);
129 } 131 }
130 } 132 }
OLDNEW
« src/shared/Communication.cpp ('K') | « src/shared/Communication.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld