| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/installer/mini_installer/regkey.h" | 5 #include "chrome/installer/mini_installer/regkey.h" |
| 6 | 6 |
| 7 #include "chrome/installer/mini_installer/mini_installer_constants.h" | 7 #include "chrome/installer/mini_installer/mini_installer_constants.h" |
| 8 #include "chrome/installer/mini_installer/mini_string.h" | 8 #include "chrome/installer/mini_installer/mini_string.h" |
| 9 | 9 |
| 10 namespace mini_installer { | 10 namespace mini_installer { |
| 11 | 11 |
| 12 LONG RegKey::Open(HKEY key, const wchar_t* sub_key, REGSAM access) { | 12 LONG RegKey::Open(HKEY key, const wchar_t* sub_key, REGSAM access) { |
| 13 Close(); | 13 Close(); |
| 14 return ::RegOpenKeyEx(key, sub_key, NULL, access, &key_); | 14 return ::RegOpenKeyEx(key, sub_key, NULL, access, &key_); |
| 15 } | 15 } |
| 16 | 16 |
| 17 LONG RegKey::ReadSZValue(const wchar_t* value_name, | 17 LONG RegKey::ReadSZValue(const wchar_t* value_name, |
| 18 wchar_t* value, | 18 wchar_t* value, |
| 19 size_t value_size) const { | 19 size_t value_size) const { |
| 20 DWORD type = 0; | 20 DWORD type = 0; |
| 21 DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t)); | 21 DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t)); |
| 22 LONG result = ::RegQueryValueEx(key_, value_name, NULL, &type, | 22 LONG result = ::RegQueryValueEx(key_, value_name, NULL, &type, |
| 23 reinterpret_cast<BYTE*>(value), | 23 reinterpret_cast<BYTE*>(value), |
| 24 &byte_length); | 24 &byte_length); |
| 25 if (result == ERROR_SUCCESS) { | 25 if (result == ERROR_SUCCESS) { |
| 26 if (type != REG_SZ) { | 26 if (type != REG_SZ) { |
| 27 result = ERROR_NOT_SUPPORTED; | 27 result = ERROR_NOT_SUPPORTED; |
| 28 } else if (byte_length == 0) { | 28 } else if (byte_length < 2) { |
| 29 *value = L'\0'; | 29 *value = L'\0'; |
| 30 } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') { | 30 } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') { |
| 31 if ((byte_length / sizeof(wchar_t)) < value_size) | 31 if ((byte_length / sizeof(wchar_t)) < value_size) |
| 32 value[byte_length / sizeof(wchar_t)] = L'\0'; | 32 value[byte_length / sizeof(wchar_t)] = L'\0'; |
| 33 else | 33 else |
| 34 result = ERROR_MORE_DATA; | 34 result = ERROR_MORE_DATA; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 return result; | 37 return result; |
| 38 } | 38 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (!client_state_key.assign(kClientStateKeyBase)) | 105 if (!client_state_key.assign(kClientStateKeyBase)) |
| 106 return ERROR_BUFFER_OVERFLOW; | 106 return ERROR_BUFFER_OVERFLOW; |
| 107 #if defined(GOOGLE_CHROME_BUILD) | 107 #if defined(GOOGLE_CHROME_BUILD) |
| 108 if (!client_state_key.append(app_guid)) | 108 if (!client_state_key.append(app_guid)) |
| 109 return ERROR_BUFFER_OVERFLOW; | 109 return ERROR_BUFFER_OVERFLOW; |
| 110 #endif | 110 #endif |
| 111 return key->Open(root_key, client_state_key.get(), access | KEY_WOW64_32KEY); | 111 return key->Open(root_key, client_state_key.get(), access | KEY_WOW64_32KEY); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace mini_installer | 114 } // namespace mini_installer |
| OLD | NEW |