Commit c006ff2a authored by Nico Weber's avatar Nico Weber

More compiler whack-a-mole.

clang didn't like the reinterpret_cast either:
..\..\sandbox\win\sandbox_poc\pocdll\registry.cc(24,10) :  error(clang): case value is not a constant expression
    case reinterpret_cast<LONG_PTR>(HKEY_USERS):
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..\..\sandbox\win\sandbox_poc\pocdll\registry.cc(24,10) :  note(clang): reinterpret_cast is not allowed in a constant expression

Since this function doesn't prevent any duplication, just kill
it and pass the string to Try() manually.

No behavior change.

BUG=82385
R=cpu@chromium.org

Review URL: https://codereview.chromium.org/543153002

Cr-Commit-Position: refs/heads/master@{#293580}
parent 6643d002
......@@ -7,29 +7,12 @@
// This file contains the tests used to verify the security of the registry.
// Converts an HKEY to a string. This is using the lazy way and works only
// for the main hives.
// "key" is the hive to convert to string.
// The return value is the string corresponding to the hive or "unknown"
const wchar_t *HKEYToString(const HKEY key) {
switch (reinterpret_cast<LONG_PTR>(key)) {
case reinterpret_cast<LONG_PTR>(HKEY_CLASSES_ROOT):
return L"HKEY_CLASSES_ROOT";
case reinterpret_cast<LONG_PTR>(HKEY_CURRENT_CONFIG):
return L"HKEY_CURRENT_CONFIG";
case reinterpret_cast<LONG_PTR>(HKEY_CURRENT_USER):
return L"HKEY_CURRENT_USER";
case reinterpret_cast<LONG_PTR>(HKEY_LOCAL_MACHINE):
return L"HKEY_LOCAL_MACHINE";
case reinterpret_cast<LONG_PTR>(HKEY_USERS):
return L"HKEY_USERS";
}
return L"unknown";
}
// Tries to open the key hive\path and outputs the result.
// "output" is the stream used for logging.
void TryOpenKey(const HKEY hive, const wchar_t *path, FILE *output) {
void TryOpenKey(const HKEY hive,
const wchar_t* hive_name,
const wchar_t* path,
FILE* output) {
HKEY key;
LONG err_code = ::RegOpenKeyEx(hive,
path,
......@@ -37,14 +20,16 @@ void TryOpenKey(const HKEY hive, const wchar_t *path, FILE *output) {
MAXIMUM_ALLOWED,
&key);
if (ERROR_SUCCESS == err_code) {
fprintf(output, "[GRANTED] Opening key \"%S\\%S\". Handle 0x%p\r\n",
HKEYToString(hive),
fprintf(output,
"[GRANTED] Opening key \"%S\\%S\". Handle 0x%p\r\n",
hive_name,
path,
key);
::RegCloseKey(key);
} else {
fprintf(output, "[BLOCKED] Opening key \"%S\\%S\". Error %ld\r\n",
HKEYToString(hive),
fprintf(output,
"[BLOCKED] Opening key \"%S\\%S\". Error %ld\r\n",
hive_name,
path,
err_code);
}
......@@ -54,10 +39,11 @@ void POCDLL_API TestRegistry(HANDLE log) {
HandleToFile handle2file;
FILE *output = handle2file.Translate(log, "w");
TryOpenKey(HKEY_LOCAL_MACHINE, NULL, output);
TryOpenKey(HKEY_CURRENT_USER, NULL, output);
TryOpenKey(HKEY_USERS, NULL, output);
TryOpenKey(HKEY_LOCAL_MACHINE, L"HKEY_LOCAL_MACHINE", NULL, output);
TryOpenKey(HKEY_CURRENT_USER, L"HKEY_CURRENT_USER", NULL, output);
TryOpenKey(HKEY_USERS, L"HKEY_USERS", NULL, output);
TryOpenKey(HKEY_LOCAL_MACHINE,
L"HKEY_LOCAL_MACHINE",
L"Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon",
output);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment