Skip to content

Commit 2623c07

Browse files
gaurav2699nibanks
andauthored
Removed RegDeleteTreeA usage in storage_winuser (#5182)
* added RegDeleteTreeA definition in restricted build * removed usage of RegDeleteTreeA * updated clog * max short * added comment * added RegQuertyInfKeyA * added line * Update src/platform/storage_winuser.c Co-authored-by: Nick Banks <[email protected]> --------- Co-authored-by: Nick Banks <[email protected]>
1 parent 64b9c9d commit 2623c07

File tree

3 files changed

+145
-1
lines changed

3 files changed

+145
-1
lines changed

src/generated/linux/storage_winuser.c.clog.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ tracepoint(CLOG_STORAGE_WINUSER_C, LibraryErrorStatus , arg2, arg3);\
6363

6464

6565

66+
/*----------------------------------------------------------
67+
// Decoder Ring for AllocFailure
68+
// Allocation of '%s' failed. (%llu bytes)
69+
// QuicTraceEvent(
70+
AllocFailure,
71+
"Allocation of '%s' failed. (%llu bytes)",
72+
"RegEnumValueA ValueName",
73+
AllocatedLength);
74+
// arg2 = arg2 = "RegEnumValueA ValueName" = arg2
75+
// arg3 = arg3 = AllocatedLength = arg3
76+
----------------------------------------------------------*/
77+
#ifndef _clog_4_ARGS_TRACE_AllocFailure
78+
#define _clog_4_ARGS_TRACE_AllocFailure(uniqueId, encoded_arg_string, arg2, arg3)\
79+
tracepoint(CLOG_STORAGE_WINUSER_C, AllocFailure , arg2, arg3);\
80+
81+
#endif
82+
83+
84+
85+
6686
#ifdef __cplusplus
6787
}
6888
#endif

src/generated/linux/storage_winuser.c.clog.h.lttng.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,26 @@ TRACEPOINT_EVENT(CLOG_STORAGE_WINUSER_C, LibraryErrorStatus,
4040
ctf_string(arg3, arg3)
4141
)
4242
)
43+
44+
45+
46+
/*----------------------------------------------------------
47+
// Decoder Ring for AllocFailure
48+
// Allocation of '%s' failed. (%llu bytes)
49+
// QuicTraceEvent(
50+
AllocFailure,
51+
"Allocation of '%s' failed. (%llu bytes)",
52+
"RegEnumValueA ValueName",
53+
AllocatedLength);
54+
// arg2 = arg2 = "RegEnumValueA ValueName" = arg2
55+
// arg3 = arg3 = AllocatedLength = arg3
56+
----------------------------------------------------------*/
57+
TRACEPOINT_EVENT(CLOG_STORAGE_WINUSER_C, AllocFailure,
58+
TP_ARGS(
59+
const char *, arg2,
60+
unsigned long long, arg3),
61+
TP_FIELDS(
62+
ctf_string(arg2, arg2)
63+
ctf_integer(uint64_t, arg3, arg3)
64+
)
65+
)

src/platform/storage_winuser.c

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,106 @@ CxPlatStorageClear(
348348
_In_ CXPLAT_STORAGE* Storage
349349
)
350350
{
351-
return HRESULT_FROM_WIN32(RegDeleteTreeA(Storage->RegKey, NULL));
351+
//
352+
// Clear only values in this registry key, not subkeys, to preserve
353+
// separation between global and per-app settings. RegDeleteTreeA would
354+
// delete the entire subtree and wipe all app-specific data when clearing
355+
// global storage.
356+
//
357+
QUIC_STATUS Status = QUIC_STATUS_SUCCESS;
358+
DWORD Error = NO_ERROR;
359+
DWORD AllocatedLength = 0;
360+
PSTR ValueName = NULL;
361+
362+
//
363+
// Query registry key info to get the maximum value name length
364+
//
365+
Error = RegQueryInfoKeyA(
366+
Storage->RegKey,
367+
NULL, // Class
368+
NULL, // ClassLength
369+
NULL, // Reserved
370+
NULL, // SubKeys
371+
NULL, // MaxSubKeyLen
372+
NULL, // MaxClassLen
373+
NULL, // Values
374+
&AllocatedLength, // MaxValueNameLen
375+
NULL, // MaxValueLen
376+
NULL, // SecurityDescriptor
377+
NULL); // LastWriteTime
378+
if (Error != NO_ERROR) {
379+
Status = HRESULT_FROM_WIN32(Error);
380+
QuicTraceEvent(
381+
LibraryErrorStatus,
382+
"[ lib] ERROR, %u, %s.",
383+
Status,
384+
"RegQueryInfoKeyA failed");
385+
goto Exit;
386+
}
387+
//
388+
// Add 1 for null terminator (RegQueryInfoKeyA returns length without null terminator)
389+
//
390+
AllocatedLength++;
391+
392+
ValueName = CXPLAT_ALLOC_PAGED(AllocatedLength, QUIC_POOL_PLATFORM_TMP_ALLOC);
393+
if (ValueName == NULL) {
394+
Status = QUIC_STATUS_OUT_OF_MEMORY;
395+
QuicTraceEvent(
396+
AllocFailure,
397+
"Allocation of '%s' failed. (%llu bytes)",
398+
"RegEnumValueA ValueName",
399+
AllocatedLength);
400+
goto Exit;
401+
}
402+
403+
//
404+
// Iterate through all values and delete them
405+
// We always use index 0 because deletion shifts the remaining values
406+
//
407+
while (TRUE) {
408+
DWORD NameLength = AllocatedLength;
409+
Error =
410+
RegEnumValueA(
411+
Storage->RegKey,
412+
0, // Always use index 0 since we delete as we go
413+
ValueName,
414+
&NameLength,
415+
NULL, // Reserved
416+
NULL, // Type
417+
NULL, // Data
418+
NULL); // DataLength
419+
420+
if (Error == ERROR_NO_MORE_ITEMS) {
421+
Status = QUIC_STATUS_SUCCESS;
422+
break;
423+
} else if (Error != NO_ERROR) {
424+
Status = HRESULT_FROM_WIN32(Error);
425+
QuicTraceEvent(
426+
LibraryErrorStatus,
427+
"[ lib] ERROR, %u, %s.",
428+
Status,
429+
"RegEnumValueA failed");
430+
goto Exit;
431+
}
432+
433+
//
434+
// Delete this value
435+
//
436+
Status = RegDeleteValueA(Storage->RegKey, ValueName);
437+
if (QUIC_FAILED(Status)) {
438+
QuicTraceEvent(
439+
LibraryErrorStatus,
440+
"[ lib] ERROR, %u, %s.",
441+
Status,
442+
"ZwDeleteValueKey failed");
443+
goto Exit;
444+
}
445+
}
446+
447+
Exit:
448+
if (ValueName != NULL) {
449+
CXPLAT_FREE(ValueName, QUIC_POOL_PLATFORM_TMP_ALLOC);
450+
}
451+
452+
return Status;
352453
}

0 commit comments

Comments
 (0)