Repository navigation
Fix Unix socket paths and array bounds in the JNI code - #97
Merged
Merged
Conversation
Unix socket paths have a size limit: 104 bytes on macOS, 108 on Linux. The JNI code copied the path into a fixed-size buffer without checking its length, so a longer path overwrote memory and crashed the JVM. Such paths are realistic, for example under ~/.sbt in a deep home directory. Now bind and connect throw an IOException for a path that is too long, as the JNA code already did. Two related bugs in connect are fixed too: it passed the number of characters in the path instead of the number of bytes, so paths with non-ASCII characters failed, and it leaked the socket when it failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write(b, off, len) didn't check that off and len are within the array. With JNI, the native code then read past the end of the array and sent whatever memory came after it over the socket. read(b, off, len) only noticed bad bounds after it had already consumed the data. Now both throw IndexOutOfBoundsException before doing anything, as InputStream and OutputStream require. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two memory safety bugs in the JNI code for Unix sockets:
IOException, as with JNA.write(b, off, len)withoffandlenoutside the array sent the memory after the array over the socket. The streams now check the bounds.The commit messages have the details.