Skip to content

Fix metadata label leak in WH_KEY_EXPORT error response#316

Open
jackctj117 wants to merge 2 commits intomainfrom
Key-export-leak
Open

Fix metadata label leak in WH_KEY_EXPORT error response#316
jackctj117 wants to merge 2 commits intomainfrom
Key-export-leak

Conversation

@jackctj117
Copy link
Contributor

This pull request contains a minor code change that adjusts the placement of the memcpy operation in the wh_Server_HandleKeyRequest function. The memcpy call, 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.

  • The memcpy statement copying the key label to resp.label in wh_Server_HandleKeyRequest is now executed outside the error check, ensuring the label is set in the response regardless of error status. (src/wh_server_keystore.c)

Copilot AI review requested due to automatic review settings March 19, 2026 21:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 memcpy that populates resp.label in WH_KEY_EXPORT handling.
  • 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.

Comment on lines 1872 to 1876
/* Only provide key output if no error */
if (ret == WH_ERROR_OK) {
resp.len = keySz;
memcpy(resp.label, meta->label, sizeof(meta->label));
}
Copy link

Copilot AI Mar 19, 2026

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_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).

Copilot uses AI. Check for mistakes.
Comment on lines 1873 to 1876
if (ret == WH_ERROR_OK) {
resp.len = keySz;
memcpy(resp.label, meta->label, sizeof(meta->label));
}
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants