Skip to content

WolfSSLEngine ByteBuffer offset/bounds fixes and JNI arrayOffset honoring#360

Merged
cconlon merged 7 commits intowolfSSL:masterfrom
JeremiahM37:fenrir-fixes-3
Apr 29, 2026
Merged

WolfSSLEngine ByteBuffer offset/bounds fixes and JNI arrayOffset honoring#360
cconlon merged 7 commits intowolfSSL:masterfrom
JeremiahM37:fenrir-fixes-3

Conversation

@JeremiahM37
Copy link
Copy Markdown
Contributor

@JeremiahM37 JeremiahM37 commented Apr 28, 2026

Fixes F-3487, F-3488, F-3489, F-3490, F-3492

  • F-3490: SendAppData pos[]/limit[] OOB when ofst > 0 (re-indexed to i-ofst)
  • F-3487: closeOutbound pre-handshake now closes inBound (was leaving it open)
  • F-3488: wrap() null-check loop bound i<len -> i<ofst+len
  • F-3489: unwrap() null/readOnly-check loop bound i<length -> i<ofst+length
  • F-3492: read/write JNI now honors ByteBuffer.arrayOffset() for sliced buffers

Added regression tests

@JeremiahM37 JeremiahM37 self-assigned this Apr 28, 2026
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #360

Scan targets checked: wolfssljni-bugs, wolfssljni-src

No new issues found in the changed files. ✅

Copy link
Copy Markdown

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 SSLEngine/WolfSSLSession ByteBuffer offset/bounds issues (including JNI honoring ByteBuffer.arrayOffset()), and adds regression tests to prevent reintroduction.

Changes:

  • Fix WolfSSLEngine buffer-array offset handling (pos/limit indexing) and correct wrap/unwrap argument-validation loop bounds.
  • Ensure closeOutbound() pre-handshake also closes inbound so isInboundDone() reflects completion.
  • Update JNI ByteBuffer read/write paths to honor ByteBuffer.arrayOffset() for sliced/duplicated heap buffers, plus add regression tests.

Reviewed changes

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

Show a summary per file
File Description
src/java/com/wolfssl/provider/jsse/WolfSSLEngine.java Fixes offset indexing/OOB issues in wrap/unwrap and SendAppData; adjusts pre-handshake closeOutbound inbound state.
native/com_wolfssl_globals.h Adds cached JNI method ID declaration for ByteBuffer.arrayOffset().
native/com_wolfssl_WolfSSL.c Caches ByteBuffer.arrayOffset() method ID during JNI_OnLoad and clears it on unload.
native/com_wolfssl_WolfSSLSession.c Applies arrayOffset + position when reading/writing array-backed ByteBuffers in JNI.
src/test/com/wolfssl/test/WolfSSLSessionTest.java Adds regression test ensuring read(ByteBuffer) honors arrayOffset() for sliced heap buffers.
src/test/com/wolfssl/provider/jsse/test/WolfSSLEngineTest.java Adds regression tests for closeOutbound pre-handshake and wrap/unwrap buffer-array offset validation.

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

Comment thread src/test/com/wolfssl/test/WolfSSLSessionTest.java Outdated
Comment thread src/test/com/wolfssl/test/WolfSSLSessionTest.java Outdated
Comment thread src/test/com/wolfssl/test/WolfSSLSessionTest.java Outdated
@cconlon cconlon merged commit 57f35cf into wolfSSL:master Apr 29, 2026
92 checks passed
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