Skip to content

Commit

Permalink
native: Do not process ancillary messages upon recvmsg error
Browse files Browse the repository at this point in the history
Previously, when trying to receive ancillary messages, a failing call to
recvmsg (returning -1 with some errno) would still attempt to parse
ancillary messages stored in the receive buffer.

This would, under some circumstances and relatively sporadically, for
example when using nonblocking sockets, return duplicate file
descriptors (e.g, see
FileDescriptorsTest.testSendRecvFileDescriptorsChannelNonBlocking)

Detect the error case and skip parsing of ancillary messages.
  • Loading branch information
kohlschuetter committed Sep 12, 2024
1 parent 46f8ce6 commit 28135bd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion junixsocket-native/src/main/c/receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static ssize_t recvmsg_wrapper(JNIEnv * env, int handle, jbyte *buf, jint length
controlLen = msg.msg_controllen;
control = msg.msg_control;

if(controlLen <= 0 || control == NULL || ancSupp == NULL) {
if(count < 0 || controlLen <= 0 || control == NULL || ancSupp == NULL) {
return count;
}

Expand Down
1 change: 1 addition & 0 deletions src/site/markdown/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ artifact (`<type>pom</type>`); see [Add junixsocket to your project](dependency.
### _(2024-XX-XX)_ **junixsocket 2.10.1**

- Fix left-over temporary library files on Windows
- Fix duplicate file descriptors being received sporadically for non-blocking sockets and upon error
- Fix a flaky selftest when VSOCK is not supported
- Improve interoperability with exotic Linux/Java combinations
- Add support for loongarch64 Linux
Expand Down

0 comments on commit 28135bd

Please sign in to comment.