echosrv: fix undersized realloc in start_listen_sockets()

sizeof(*sockfd) is the size of a pointer, not of struct listen_endpoint,
so the second listen address overflows the buffer and corrupts the heap.
This makes echosrv segfault on armhf and the test suite fail.
This commit is contained in:
Sebastien Bacher authored and Yves Rutschle committed 2026-10-27 22:07:56 +01:00
1 parent 39d164f5a8
commit e722274b63
1 file changed
+1 -1
+1 -1
View File
@@ -318,7 +318,7 @@ int start_listen_sockets(struct listen_endpoint *sockfd[])
for (addr = start_addr; addr; addr = addr->ai_next) {
num_addr++;
*sockfd = realloc(*sockfd, num_addr * sizeof(*sockfd));
*sockfd = realloc(*sockfd, num_addr * sizeof(**sockfd));
(*sockfd)[num_addr-1].socketfd = listen_single_addr(addr, keepalive, udp);
(*sockfd)[num_addr-1].type = udp ? SOCK_DGRAM : SOCK_STREAM;
fprintf(stderr, "%d:\t%s\n", (*sockfd)[num_addr-1].socketfd, sprintaddr(buf, sizeof(buf), addr));