Skip to content

Commit 28135bd

Browse files
committed
native: Do not process ancillary messages upon recvmsg error
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.
1 parent 46f8ce6 commit 28135bd

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

junixsocket-native/src/main/c/receive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static ssize_t recvmsg_wrapper(JNIEnv * env, int handle, jbyte *buf, jint length
130130
controlLen = msg.msg_controllen;
131131
control = msg.msg_control;
132132

133-
if(controlLen <= 0 || control == NULL || ancSupp == NULL) {
133+
if(count < 0 || controlLen <= 0 || control == NULL || ancSupp == NULL) {
134134
return count;
135135
}
136136

src/site/markdown/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ artifact (`<type>pom</type>`); see [Add junixsocket to your project](dependency.
1515
### _(2024-XX-XX)_ **junixsocket 2.10.1**
1616

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

0 commit comments

Comments
 (0)