From d1c7b926f3d335b7895aaa54ad3da66592012d31 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 5 Oct 2021 19:47:35 +0200 Subject: [PATCH] gluon-neighbour-info: avoid recv() with NULL buffer 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: 531937cf6f3c ("gluon-neighbour-info: fix broken output with large results") --- package/gluon-neighbour-info/src/gluon-neighbour-info.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package/gluon-neighbour-info/src/gluon-neighbour-info.c b/package/gluon-neighbour-info/src/gluon-neighbour-info.c index 119aaddc..a45a94c8 100644 --- a/package/gluon-neighbour-info/src/gluon-neighbour-info.c +++ b/package/gluon-neighbour-info/src/gluon-neighbour-info.c @@ -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)); - recvlen = recv(socket, NULL, 0, MSG_PEEK | MSG_TRUNC); + recvlen = recv(socket, *recvbuffer, 0, MSG_PEEK | MSG_TRUNC); if (recvlen < 0) return recvlen; @@ -269,6 +269,8 @@ int main(int argc, char **argv) { fflush(stdout); } + resize_recvbuffer(&recvbuffer, &recvbuffer_len, 8192); + do { ret = request(sock, &recvbuffer, &recvbuffer_len, &client_addr, request_string, sse, timeout, max_count);