Fix metadata label leak in WH_KEY_EXPORT error response#316
Fix metadata label leak in WH_KEY_EXPORT error response#316jackctj117 wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets the WH_KEY_EXPORT server handler to address label handling in export responses, specifically around error-path behavior.
Changes:
- Moves the
memcpythat populatesresp.labelinWH_KEY_EXPORThandling. - Updates when the label is included in the export response relative to
ret == WH_ERROR_OK.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* Only provide key output if no error */ | ||
| if (ret == WH_ERROR_OK) { | ||
| resp.len = keySz; | ||
| memcpy(resp.label, meta->label, sizeof(meta->label)); | ||
| } |
There was a problem hiding this comment.
Moving the label memcpy inside the ret == WH_ERROR_OK block leaves resp.label uninitialized on error paths. wh_MessageKeystore_TranslateExportResponse() always memcpy’s src->label into the outgoing packet, and *out_resp_size always includes sizeof(resp), so this can leak stack bytes to the client when WH_KEY_EXPORT fails. Initialize resp (e.g., zero-init the struct or at least resp.label) and explicitly set the label deterministically on failure (either zero it or copy meta->label, depending on intended API semantics).
| if (ret == WH_ERROR_OK) { | ||
| resp.len = keySz; | ||
| memcpy(resp.label, meta->label, sizeof(meta->label)); | ||
| } |
There was a problem hiding this comment.
This change places the memcpy(resp.label, ...) inside the success-only branch, but the PR title/description say the label should be set in the response regardless of error status. Please confirm the intended behavior for WH_KEY_EXPORT responses on failure (should the label be preserved, cleared, or omitted) and update either the code or the PR description accordingly.
This pull request contains a minor code change that adjusts the placement of the
memcpyoperation in thewh_Server_HandleKeyRequestfunction. Thememcpycall, which copies the key label, is now executed regardless of whether an error occurred, rather than only when there is no error. This ensures the label is always set in the response.memcpystatement copying the key label toresp.labelinwh_Server_HandleKeyRequestis now executed outside the error check, ensuring the label is set in the response regardless of error status. (src/wh_server_keystore.c)