]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: preset the port of fd-based "sockets" to zero
authorWilly Tarreau <w@1wt.eu>
Sat, 15 Dec 2018 14:40:12 +0000 (15:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 15 Dec 2018 14:40:12 +0000 (15:40 +0100)
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

index a33ad9bd6f57d593f6daaf1d2a56d718db71c229..6729e89be85ebb755bd48abaabb14ef9ea9050ba 100644 (file)
@@ -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);