Skip to content

BIO improvements and fixes#10164

Open
rizlik wants to merge 5 commits intowolfSSL:masterfrom
rizlik:bio
Open

BIO improvements and fixes#10164
rizlik wants to merge 5 commits intowolfSSL:masterfrom
rizlik:bio

Conversation

@rizlik
Copy link
Copy Markdown
Contributor

@rizlik rizlik commented Apr 8, 2026

Description

  • simplify wolfSSL_BIO_set_conn_hostname, fixing OOB read
  • restructure wolfSSL_BIO_ctrl_pending, fixing inverted check and
  • ctrlCB checking
  • return WOLFSSL_FAILURE in wolfSSL_BIO_up_ref when refInc fails,
    updated test to reflect this
  • check arguments for NULL in wolfSSL_BIO_ADDR_size
  • replace non-portable type long usigned int with size_t
  • wolfSSL_BIO_MEMORY_write: return WOLFSSL_BIO_ERROR on failure instead
    of WOLFSSL_FAILURE, return 0 when len is 0
  • wolfSSL_BIO_get_fp: fix type mismatch comparing XFILE* pointer against
    XBADFILE
  • wolfSSL_BIO_ctrl: add NULL check on bio before switch
  • wolfSSL_BIO_pop: clear bio prev and next pointers after unlinking
  • wolfSSL_BIO_gets: place null terminator after actual bytes read from
    BIO_BIO nread

Fixes zd#21528

Copilot AI review requested due to automatic review settings April 8, 2026 15:38
@rizlik rizlik self-assigned this Apr 8, 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

This PR improves wolfSSL’s OpenSSL-compat BIO layer by tightening argument validation, correcting return/error semantics, fixing a reported OOB read, and adding targeted regression tests (zd#21528).

Changes:

  • Fixes/reshapes several BIO behaviors (ctrl/ctrl_pending traversal, BIO_gets NUL termination, BIO_pop unlink safety, BIO_up_ref failure handling, BIO_get_fp argument checking).
  • Adjusts MEM BIO write semantics to return WOLFSSL_BIO_ERROR on failure and 0 on zero-length writes; updates tests and adds new regression tests for hostname and pending traversal.
  • Adds a BIO method type upper bound (WOLFSSL_MAX_BIO_TYPE) and enforces it in wolfSSL_BIO_meth_new().

Reviewed changes

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

File Description
wolfssl/ssl.h Introduces WOLFSSL_MAX_BIO_TYPE to bound custom BIO method types.
tests/api/test_ossl_bio.h Registers two new BIO regression tests in the test declaration list.
tests/api/test_ossl_bio.c Updates an existing expectation for MEM BIO write failure and adds new tests for BIO_set_conn_hostname and chained BIO_ctrl_pending.
src/bio.c Implements the BIO fixes/improvements across MEM BIO write, ctrl/ctrl_pending, gets termination, addr size NULL handling, get_fp arg validation, meth_new type bounds, conn hostname allocation logic, and pop unlink cleanup.

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

rizlik added 3 commits April 8, 2026 18:49
* simplify wolfSSL_BIO_set_conn_hostname, fixing OOB read
* restructure wolfSSL_BIO_ctrl_pending, fixing inverted check and
* ctrlCB checking
* return WOLFSSL_FAILURE in wolfSSL_BIO_up_ref when refInc fails,
  updated test to reflect this
* check arguments for NULL in wolfSSL_BIO_ADDR_size
* replace non-portable type long usigned int with size_t
* wolfSSL_BIO_MEMORY_write: return WOLFSSL_BIO_ERROR on failure instead
  of WOLFSSL_FAILURE, return 0 when len is 0
* wolfSSL_BIO_get_fp: fix type mismatch comparing XFILE* pointer against
  XBADFILE
* wolfSSL_BIO_ctrl: add NULL check on bio before switch
* wolfSSL_BIO_pop: clear bio prev and next pointers after unlinking
* wolfSSL_BIO_gets: place null terminator after actual bytes read from
  BIO_BIO nread
@julek-wolfssl julek-wolfssl assigned rizlik and unassigned julek-wolfssl Apr 9, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 13:19
@rizlik rizlik assigned julek-wolfssl and unassigned rizlik Apr 9, 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

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


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

julek-wolfssl
julek-wolfssl previously approved these changes Apr 9, 2026
Copy link
Copy Markdown
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

🐺 Skoll Code Review

Overall recommendation: APPROVE
Findings: 6 total — 2 posted, 4 skipped

Posted findings

  • [Info] Stale comment still references WOLFSSL_FAILURE in wolfSSL_BIO_MEMORY_writesrc/bio.c:595-596
  • [Medium] wolfSSL_BIO_ctrl_pending: ctrlCb check could dispatch to callback for built-in wrapper BIO types in chainsrc/bio.c:1308-1314
Skipped findings
  • [Medium] test_wolfSSL_BIO_set_conn_hostname does not verify stored hostname value
  • [Medium] No test coverage for wolfSSL_BIO_pop prev/next clearing
  • [Medium] No test for wolfSSL_BIO_up_ref failure return when WOLFSSL_REFCNT_ERROR_RETURN is defined
  • [Low] wolfSSL_BIO_MEMORY_write returns 0 for bio==NULL but callers may not expect this

Review generated by Skoll via openclaw

@rizlik rizlik removed their assignment Apr 10, 2026
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.

5 participants