gluon-neighbour-info: avoid recv() with NULL buffer (#2323)

Calling functions like recv() with a NULL buffer is not explicitly
allowed by the POSIX standard, so it must be avoided to be portable
across different libc implementations. Allocate an initial buffer before
handling requests, and also pass this buffer to the peek recv() call.

Fixes: 531937cf6f ("gluon-neighbour-info: fix broken output with large results")
This commit is contained in:
Matthias Schiffer 2021-10-16 14:01:34 +02:00 committed by GitHub
parent f910cab618
commit 51a1708453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,7 +95,7 @@ ssize_t recvtimeout(int socket, char **recvbuffer, size_t *recvbuffer_len,
setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout_left, sizeof(timeout_left)); setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout_left, sizeof(timeout_left));
recvlen = recv(socket, NULL, 0, MSG_PEEK | MSG_TRUNC); recvlen = recv(socket, *recvbuffer, 0, MSG_PEEK | MSG_TRUNC);
if (recvlen < 0) if (recvlen < 0)
return recvlen; return recvlen;
@ -269,6 +269,8 @@ int main(int argc, char **argv) {
fflush(stdout); fflush(stdout);
} }
resize_recvbuffer(&recvbuffer, &recvbuffer_len, 8192);
do { do {
ret = request(sock, &recvbuffer, &recvbuffer_len, &client_addr, ret = request(sock, &recvbuffer, &recvbuffer_len, &client_addr,
request_string, sse, timeout, max_count); request_string, sse, timeout, max_count);