From 0205a4e0b51287959f329f6a00f432e4d48de346 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 15 Dec 2018 15:40:12 +0100 Subject: [PATCH] MINOR: tools: preset the port of fd-based "sockets" to zero Addresses made of a file descriptor store the file descriptor into the address part of a sin_addr. Contrary to other address classes, there's no way to figure later based on the FD if an initialization was done (which is how logs initialize their FDs). The port part is currently left with random data, so let's instead specifically set the port part to zero when creating an FD, and let the code using it set whatever info it needs there, typically an initialization state. --- src/standard.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/standard.c b/src/standard.c index a33ad9bd6..6729e89be 100644 --- a/src/standard.c +++ b/src/standard.c @@ -900,6 +900,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int str2 += 9; ((struct sockaddr_in *)&ss)->sin_addr.s_addr = strtol(str2, &endptr, 10); + ((struct sockaddr_in *)&ss)->sin_port = 0; if (!*str2 || *endptr) { memprintf(err, "file descriptor '%s' is not a valid integer in '%s'\n", str2, str); @@ -914,6 +915,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int str2 += 3; ((struct sockaddr_in *)&ss)->sin_addr.s_addr = strtol(str2, &endptr, 10); + ((struct sockaddr_in *)&ss)->sin_port = 0; if (!*str2 || *endptr) { memprintf(err, "file descriptor '%s' is not a valid integer in '%s'\n", str2, str);