Repository navigation
Bound the receive buffer sizes and check the socket arguments - #5
Open
MinhyukHong wants to merge 2 commits into
Open
MinhyukHong wants to merge 2 commits into
MinhyukHong wants to merge 2 commits into
Conversation
tcprecv, tcprecvuntil, udprecv, unixrecv and unixrecvuntil allocate a variable length array on the stack whose size comes straight from JavaScript. To<int> accepts negative values too, which become huge when converted to a size. A large value moves the stack pointer into unmapped memory. The VLA in udpRead uses the size udprecv stored, so bounding udprecv covers it as well.
UnwrapPointer returns NULL for anything that is not a Buffer, and that NULL goes straight into the libmill calls. Passing a number where a socket is expected dereferences it.
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.
The receive functions allocate a variable length array on the stack sized by a value that comes straight from JavaScript:
To<int>takes negative numbers as well, and those become very large when used as a size. A big value moves the stack pointer past the end of the stack. This affectstcprecv,tcprecvuntil,udprecv,unixrecvandunixrecvuntil; the VLA inudpReaduses the sizeudprecvstored, so it is covered onceudprecvchecks it.The second commit adds a type check on the socket argument.
UnwrapPointerreturns NULL for anything that is not a Buffer, and that NULL is passed on to the libmill calls as it is.1 MiB is a guess at a reasonable ceiling — happy to change it.
Distinguishing a tcpsock handle from a unixsock handle would need the wrapped pointers to carry a tag, so this only checks that the argument is a handle at all.