From: Willy Tarreau Date: Sat, 15 Dec 2018 14:40:12 +0000 (+0100) Subject: MINOR: tools: preset the port of fd-based "sockets" to zero X-Git-Tag: v1.9-dev11~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0205a4e0b51287959f329f6a00f432e4d48de346;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/standard.c b/src/standard.c index a33ad9bd6f..6729e89be8 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);