Skip to content

Fix multiple bugs in OCSP implementation#10115

Open
julek-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
julek-wolfssl:zd/21469
Open

Fix multiple bugs in OCSP implementation#10115
julek-wolfssl wants to merge 1 commit intowolfSSL:masterfrom
julek-wolfssl:zd/21469

Conversation

@julek-wolfssl
Copy link
Copy Markdown
Member

  • wolfSSL_i2d_OCSP_REQUEST_bio: save/restore pointer before i2d call
    that advances it, preventing BIO_write from wrong offset and heap
    corruption on free
  • wolfSSL_d2i_OCSP_RESPONSE: remove (unsigned char) cast that truncated
    pointer advance to 8 bits, breaking responses larger than 255 bytes
  • wolfSSL_OCSP_CERTID_dup: deep-copy CertStatus to prevent double-free
    when both original and duplicate are freed
  • wolfSSL_i2d_OCSP_RESPONSE: add NULL check on response parameter
  • wolfSSL_i2d_OCSP_REQUEST: advance *data pointer per i2d convention
  • FreeOCSP: NULL-check ocsp->cm before dereferencing for heap
  • Fix WOLFSSL_LEAVE strings to match actual function names in
    wc_CheckCertOcspResponse, GetOcspEntry, GetOcspStatus,
    CheckOcspResponse, CheckOcspRequest

Add test for CERTID dup (double-free confirmed under ASAN without fix)
and pointer advancement assertions for d2i_OCSP_RESPONSE callers.

Reported in: ZD21469

@julek-wolfssl julek-wolfssl self-assigned this Apr 1, 2026
Copilot AI review requested due to automatic review settings April 1, 2026 13:31
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 several correctness issues in the OCSP encode/decode and CERTID duplication paths, and adds regression tests to prevent pointer-advancement and double-free regressions.

Changes:

  • Correct pointer advancement / i2d+d2i conventions for OCSP request/response encoding/decoding.
  • Fix CERTID duplication to deep-copy status and avoid double-free.
  • Add tests asserting d2i pointer advancement and validating CERTID dup safety under ASAN.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/api/test_ocsp.h Declares the new OCSP CERTID duplication test.
tests/api/test_ocsp.c Adds pointer-advancement assertions for d2i and a new CERTID-dup regression test.
tests/api.c Adds d2i pointer-advancement assertions and registers the new CERTID-dup test.
src/ocsp.c Fixes OCSP pointer advancement, null handling, heap usage on free, and deep-copy logic in CERTID duplication.

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

- wolfSSL_i2d_OCSP_REQUEST_bio: save/restore pointer before i2d call
  that advances it, preventing BIO_write from wrong offset and heap
  corruption on free
- wolfSSL_d2i_OCSP_RESPONSE: remove (unsigned char) cast that truncated
  pointer advance to 8 bits, breaking responses larger than 255 bytes
- wolfSSL_OCSP_CERTID_dup: deep-copy CertStatus to prevent double-free
  when both original and duplicate are freed
- wolfSSL_i2d_OCSP_RESPONSE: add NULL check on response parameter
- wolfSSL_i2d_OCSP_REQUEST: advance *data pointer per i2d convention
- FreeOCSP: NULL-check ocsp->cm before dereferencing for heap
- Fix WOLFSSL_LEAVE strings to match actual function names in
  wc_CheckCertOcspResponse, GetOcspEntry, GetOcspStatus,
  CheckOcspResponse, CheckOcspRequest

Add test for CERTID dup (double-free confirmed under ASAN without fix)
and pointer advancement assertions for d2i_OCSP_RESPONSE callers.

Reported in: ZD21469
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.

2 participants