Skip to content

ecc: fix double-free in wc_ecc_import_point_der_ex on invalid format byte#10592

Open
MarkAtwood wants to merge 1 commit into
wolfSSL:masterfrom
MarkAtwood:fix/ecc-double-free-invalid-format-byte
Open

ecc: fix double-free in wc_ecc_import_point_der_ex on invalid format byte#10592
MarkAtwood wants to merge 1 commit into
wolfSSL:masterfrom
MarkAtwood:fix/ecc-double-free-invalid-format-byte

Conversation

@MarkAtwood
Copy link
Copy Markdown
Contributor

Summary

wc_ecc_import_point_der_ex crashes (double-free/SIGABRT) when given a full-length EC point blob with an invalid first byte (e.g. 0x01, 0x05, 0xFF). The format byte check happened after mp_clear(point->x/y) and memory initialization, so on error the cleanup path freed already-freed memory.

Fix

Move the format byte validation (0x02, 0x03, or 0x04) before any memory operations (mp_clear, mp_init). Return ASN_PARSE_E immediately on invalid format byte, before any state is touched.

Reproducer

Call wc_ecc_import_point_der_ex with a buffer whose first byte is 0x05 (or any value other than 0x02, 0x03, 0x04). Before this fix it crashes; after, it returns ASN_PARSE_E.

Test Plan

  • Invalid format byte (0x01, 0x05, 0xFF) returns ASN_PARSE_E without crash
  • Valid uncompressed (0x04) and compressed (0x02, 0x03) points still import correctly
  • Run existing wolfSSL test suite

…byte

wc_ecc_import_point_der_ex crashed (double-free/SIGABRT) when given
a full-length EC point blob with an invalid first byte (0x01, 0x05,
0xFF, etc.). The function fell through to code paths that partially
initialized state, then the cleanup path freed already-freed memory.

Add early validation of the format byte and fix cleanup paths to
prevent double-free on error.
Copilot AI review requested due to automatic review settings June 3, 2026 23:29
@MarkAtwood MarkAtwood self-assigned this Jun 3, 2026
Copy link
Copy Markdown
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

Fixes a crash (double-free/SIGABRT) in wc_ecc_import_point_der_ex() when importing an EC point whose first/format byte is invalid, by validating the format byte before any mp_clear() / mp_init_*() operations touch the destination point.

Changes:

  • Validate the point format byte (0x02, 0x03, 0x04) immediately after basic argument/length checks.
  • Return ASN_PARSE_E early on invalid format byte, avoiding mutation/cleanup of point state.
  • Remove the later (post-init) point-type validation and rely on the earlier check.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wolfcrypt/src/ecc.c
@ColtonWilley
Copy link
Copy Markdown
Contributor

Jenkins retest this please

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.

4 participants