-
Notifications
You must be signed in to change notification settings - Fork 677
Removed RegDeleteTreeA usage in storage_winuser #5182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ef78c74
5f3013d
dfe8a1a
4322d02
dc97266
567acca
a19d347
80e66b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,5 +348,122 @@ CxPlatStorageClear( | |
| _In_ CXPLAT_STORAGE* Storage | ||
| ) | ||
| { | ||
| return HRESULT_FROM_WIN32(RegDeleteTreeA(Storage->RegKey, NULL)); | ||
| } | ||
| // | ||
| // Clear only values in this registry key, not subkeys, to preserve | ||
| // separation between global and per-app settings. RegDeleteTreeA would | ||
| // delete the entire subtree and wipe all app-specific data when clearing | ||
| // global storage. | ||
| // | ||
| QUIC_STATUS Status = QUIC_STATUS_SUCCESS; | ||
| DWORD Error = NO_ERROR; | ||
| DWORD AllocatedLength = 255; | ||
| PSTR ValueName = NULL; | ||
|
|
||
| ValueName = CXPLAT_ALLOC_PAGED(AllocatedLength, QUIC_POOL_PLATFORM_TMP_ALLOC); | ||
| if (ValueName == NULL) { | ||
| Status = QUIC_STATUS_OUT_OF_MEMORY; | ||
| QuicTraceEvent( | ||
| AllocFailure, | ||
| "Allocation of '%s' failed. (%llu bytes)", | ||
| "RegEnumValueA ValueName", | ||
| AllocatedLength); | ||
| goto Exit; | ||
| } | ||
|
|
||
| // | ||
| // Iterate through all values and delete them | ||
| // We always use index 0 because deletion shifts the remaining values | ||
| // | ||
| while (TRUE) { | ||
| DWORD NameLength = AllocatedLength; | ||
| Error = | ||
| RegEnumValueA( | ||
| Storage->RegKey, | ||
| 0, // Always use index 0 since we delete as we go | ||
| ValueName, | ||
| &NameLength, | ||
| NULL, // Reserved | ||
| NULL, // Type | ||
| NULL, // Data | ||
| NULL); // DataLength | ||
|
|
||
| while (Error == ERROR_MORE_DATA && AllocatedLength < MAXSHORT) { | ||
| // | ||
| // Reallocate buffer only if current buffer is too small | ||
| // | ||
| CXPLAT_DBG_ASSERT(ValueName != NULL); | ||
|
|
||
| CXPLAT_FREE(ValueName, QUIC_POOL_PLATFORM_TMP_ALLOC); | ||
|
|
||
| AllocatedLength *= 2; // The API doesn't tell us the needed length; just double it. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, so at the top call
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, that's the theory.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on using it then, it seems to me like a more natural pattern!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have modified it according to the suggested method, please see if it looks fine. Thanks. |
||
| if (AllocatedLength > MAXSHORT) { | ||
| // | ||
| // The registry API interprets this value as a SHORT, so | ||
| // values larger than 32,767 will cause it to overflow and | ||
| // return ERROR_MORE_DATA. So limit allocation to this length. | ||
| // | ||
| AllocatedLength = MAXSHORT; | ||
| } | ||
|
|
||
| ValueName = CXPLAT_ALLOC_PAGED(AllocatedLength, QUIC_POOL_PLATFORM_TMP_ALLOC); | ||
| if (ValueName == NULL) { | ||
| Status = QUIC_STATUS_OUT_OF_MEMORY; | ||
| QuicTraceEvent( | ||
| AllocFailure, | ||
| "Allocation of '%s' failed. (%llu bytes)", | ||
| "RegEnumValueA ValueName (realloc)", | ||
| AllocatedLength); | ||
| goto Exit; | ||
| } | ||
|
|
||
| NameLength = AllocatedLength; | ||
|
|
||
| // | ||
| // Get the value name | ||
| // | ||
| Error = | ||
| RegEnumValueA( | ||
| Storage->RegKey, | ||
| 0, // Always use index 0 since we delete as we go | ||
| ValueName, | ||
| &NameLength, | ||
| NULL, // Reserved | ||
| NULL, // Type | ||
| NULL, // Data | ||
| NULL); // DataLength | ||
| } | ||
|
|
||
| if (Error == ERROR_NO_MORE_ITEMS) { | ||
| Status = QUIC_STATUS_SUCCESS; | ||
| break; | ||
| } else if (Error != NO_ERROR) { | ||
| Status = HRESULT_FROM_WIN32(Error); | ||
| QuicTraceEvent( | ||
| LibraryErrorStatus, | ||
| "[ lib] ERROR, %u, %s.", | ||
| Status, | ||
| "RegEnumValueA failed"); | ||
| goto Exit; | ||
| } | ||
|
|
||
| // | ||
| // Delete this value | ||
| // | ||
| Status = RegDeleteValueA(Storage->RegKey, ValueName); | ||
| if (QUIC_FAILED(Status)) { | ||
| QuicTraceEvent( | ||
| LibraryErrorStatus, | ||
| "[ lib] ERROR, %u, %s.", | ||
| Status, | ||
| "ZwDeleteValueKey failed"); | ||
| goto Exit; | ||
| } | ||
| } | ||
|
|
||
| Exit: | ||
| if (ValueName != NULL) { | ||
| CXPLAT_FREE(ValueName, QUIC_POOL_PLATFORM_TMP_ALLOC); | ||
| } | ||
|
|
||
| return Status; | ||
| } | ||
|
gaurav2699 marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.