From 51a1708453dae5a61978d3383ad7580299ca092c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 16 Oct 2021 14:01:34 +0200 Subject: [PATCH] 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: 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);