From: Dmitry Timoshkov Subject: [PATCH 2/2] server: Strip terminating '\0' from the registry key name. (Resend) Message-Id: <20220125115646.e681d67765dfa016f203e9e3@baikal.ru> Date: Tue, 25 Jan 2022 11:56:46 +0300 Signed-off-by: Dmitry Timoshkov --- dlls/ntdll/tests/reg.c | 18 +++++++++++++++++- server/registry.c | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/tests/reg.c b/dlls/ntdll/tests/reg.c index 445c05a02e1..956df02fae4 100644 --- a/dlls/ntdll/tests/reg.c +++ b/dlls/ntdll/tests/reg.c @@ -456,6 +456,14 @@ todo_wine ok( status == STATUS_OBJECT_TYPE_MISMATCH, "NtOpenKey failed: 0x%08x\n", status ); pRtlFreeUnicodeString( &str ); + pRtlCreateUnicodeStringFromAsciiz( &str, "\\REGISTRY\\Machine\\Software\\Classes" ); + str.Length += sizeof(WCHAR); /* include terminating \0 in the length */ + status = pNtOpenKey( &key, KEY_READ, &attr ); + ok( status == STATUS_SUCCESS || broken(status == STATUS_OBJECT_NAME_NOT_FOUND) /* win8 */, + "NtOpenKey failed: 0x%08x\n", status ); + if (!status) pNtClose( key ); + pRtlFreeUnicodeString( &str ); + if (!pNtOpenKeyEx) { win_skip("NtOpenKeyEx not available\n"); @@ -630,13 +638,21 @@ static void test_NtCreateKey(void) status = pNtCreateKey( &subkey, am, &attr, 0, 0, 0, 0 ); ok( status == STATUS_SUCCESS, "NtCreateKey failed: 0x%08x\n", status ); - if (!status) pNtClose( subkey ); + pNtClose( subkey ); pRtlFreeUnicodeString( &str ); pRtlCreateUnicodeStringFromAsciiz( &str, "\\REGISTRY\\MACHINE\\SOFTWARE\\CLASSES" ); status = pNtCreateKey( &subkey, am, &attr, 0, 0, 0, 0 ); ok( status == STATUS_SUCCESS, "NtCreateKey failed: 0x%08x\n", status ); + pNtClose( subkey ); + pRtlFreeUnicodeString( &str ); + + pRtlCreateUnicodeStringFromAsciiz( &str, "\\REGISTRY\\Machine\\Software\\Classes" ); + str.Length += sizeof(WCHAR); /* include terminating \0 in the length */ + status = pNtCreateKey( &subkey, am, &attr, 0, 0, 0, 0 ); + ok( status == STATUS_SUCCESS || broken(status == STATUS_OBJECT_PATH_NOT_FOUND) /* win8 */, + "NtCreateKey failed: 0x%08x\n", status ); if (!status) pNtClose( subkey ); pRtlFreeUnicodeString( &str ); diff --git a/server/registry.c b/server/registry.c index 2a2bc9a4e68..6a03a41a9de 100644 --- a/server/registry.c +++ b/server/registry.c @@ -477,6 +477,8 @@ static inline void get_req_path( struct unicode_str *str ) { str->str = get_req_data(); str->len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR); + + while (str->len && !str->str[str->len / sizeof(WCHAR) - 1]) str->len -= sizeof(WCHAR); } /* return the next token in a given path */ -- 2.34.1