-
Notifications
You must be signed in to change notification settings - Fork 31
Fix metadata label leak in WH_KEY_EXPORT error response #316
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1848,7 +1848,7 @@ int wh_Server_HandleKeyRequest(whServerContext* server, uint16_t magic, | |
|
|
||
| case WH_KEY_EXPORT: { | ||
| whMessageKeystore_ExportRequest req; | ||
| whMessageKeystore_ExportResponse resp; | ||
| whMessageKeystore_ExportResponse resp = {0}; | ||
| uint32_t keySz; | ||
|
|
||
| /* translate request */ | ||
|
|
@@ -1872,8 +1872,8 @@ int wh_Server_HandleKeyRequest(whServerContext* server, uint16_t magic, | |
| /* Only provide key output if no error */ | ||
| if (ret == WH_ERROR_OK) { | ||
| resp.len = keySz; | ||
| memcpy(resp.label, meta->label, sizeof(meta->label)); | ||
| } | ||
|
Comment on lines
1873
to
1876
|
||
| memcpy(resp.label, meta->label, sizeof(meta->label)); | ||
|
|
||
| (void)WH_SERVER_NVM_UNLOCK(server); | ||
| } /* WH_SERVER_NVM_LOCK() */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the label memcpy inside the
ret == WH_ERROR_OKblock leavesresp.labeluninitialized on error paths.wh_MessageKeystore_TranslateExportResponse()always memcpy’ssrc->labelinto the outgoing packet, and*out_resp_sizealways includessizeof(resp), so this can leak stack bytes to the client whenWH_KEY_EXPORTfails. Initializeresp(e.g., zero-init the struct or at leastresp.label) and explicitly set the label deterministically on failure (either zero it or copymeta->label, depending on intended API semantics).