Skip to content

Commit

Permalink
Fix bug that uses &read for num bytes received
Browse files Browse the repository at this point in the history
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
  • Loading branch information
skrueger authored and facebook-github-bot committed Nov 23, 2024
1 parent a5443ac commit 1cbea3a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions folly/io/async/test/AsyncUDPSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,18 @@ class UDPNotifyClient : public UDPClient {
if (errno != EAGAIN || errno != EWOULDBLOCK) {
onReadError(folly::AsyncSocketException(
folly::AsyncSocketException::NETWORK_ERROR, "error"));
return;
}
}
SocketAddress addr;
addr.setFromSockaddr(rawAddr, addrLen);
} else {
// Datagram sockets in various domains (e.g., the UNIX and Internet
// domains) permit zero-length datagrams. When such a datagram is
// received, the return value is 0.
auto numBytesRecv{static_cast<size_t>(ret)};

onDataAvailable(
addr, size_t(folly::fileops::read), false, OnDataAvailableParams());
SocketAddress addr;
addr.setFromSockaddr(rawAddr, addrLen);

onDataAvailable(addr, numBytesRecv, false, OnDataAvailableParams());
}
}

void onRecvMmsg(AsyncUDPSocket& sock) {
Expand Down

0 comments on commit 1cbea3a

Please sign in to comment.