Skip to content

Bound the receive buffer sizes and check the socket arguments - #5

Open
MinhyukHong wants to merge 2 commits into
reqshark:masterfrom
MinhyukHong:fix/bound-receive-buffer-sizes
Open

MinhyukHong wants to merge 2 commits into
reqshark:masterfrom
MinhyukHong:fix/bound-receive-buffer-sizes

Conversation

@MinhyukHong

@MinhyukHong MinhyukHong commented Oct 12, 2026 •

Copy link
Copy Markdown

The receive functions allocate a variable length array on the stack sized by a value that comes straight from JavaScript:

int rcvbuf = To<int>(info[1]).FromJust();
char buf[rcvbuf];

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 affects tcprecv, tcprecvuntil, udprecv, unixrecv and unixrecvuntil; the VLA in udpRead uses the size udprecv stored, so it is covered once udprecv checks it.

The second commit adds a type check on the socket argument. UnwrapPointer returns 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.

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.
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.

1 participant