Skip to content

Commit 1cbea3a

Browse files
skruegerfacebook-github-bot
authored andcommitted
Fix bug that uses &read for num bytes received
Summary: Bug currently passes `size_t(read)`, which is the memory address of the `read` function. The correct argument is a positive `ret`, which is the length of the message in bytes. The bug is innocuous because the value is placed in a log statement and otherwise unused. I clean up the logic and only notify when `ret >= 0`. Reviewed By: ot Differential Revision: D66336105 fbshipit-source-id: ca2b95275048893aa5c1b86a5ffb534a806bc2ee
1 parent a5443ac commit 1cbea3a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

folly/io/async/test/AsyncUDPSocketTest.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,18 @@ class UDPNotifyClient : public UDPClient {
372372
if (errno != EAGAIN || errno != EWOULDBLOCK) {
373373
onReadError(folly::AsyncSocketException(
374374
folly::AsyncSocketException::NETWORK_ERROR, "error"));
375-
return;
376375
}
377-
}
378-
SocketAddress addr;
379-
addr.setFromSockaddr(rawAddr, addrLen);
376+
} else {
377+
// Datagram sockets in various domains (e.g., the UNIX and Internet
378+
// domains) permit zero-length datagrams. When such a datagram is
379+
// received, the return value is 0.
380+
auto numBytesRecv{static_cast<size_t>(ret)};
380381

381-
onDataAvailable(
382-
addr, size_t(folly::fileops::read), false, OnDataAvailableParams());
382+
SocketAddress addr;
383+
addr.setFromSockaddr(rawAddr, addrLen);
384+
385+
onDataAvailable(addr, numBytesRecv, false, OnDataAvailableParams());
386+
}
383387
}
384388

385389
void onRecvMmsg(AsyncUDPSocket& sock) {

0 commit comments

Comments
 (0)