]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CONTRIB: tcploop: use the trash instead of NULL for recv()
authorWilly Tarreau <w@1wt.eu>
Tue, 14 Mar 2017 13:50:52 +0000 (14:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 15 Mar 2017 10:48:46 +0000 (11:48 +0100)
NULL is Linux-centric and we're not focused on performance here but
portability and reproducibility. Don't use NULL and use the trash
instead. It may lead to multiple recv() calls for large blocks but
as a benefit it will be possible to see the contents with strace.

contrib/tcploop/tcploop.c

index d1995f46e4641a0fd8e268bb562ecfe92e5dfcdf..cb9e5f124643d1a9285eecf64e29fd872e855970 100644 (file)
@@ -444,6 +444,7 @@ int tcp_recv(int sock, const char *arg)
 {
        int count = -1; // stop at first read
        int ret;
+       int max;
 
        if (arg[1]) {
                count = atoi(arg + 1);
@@ -454,7 +455,10 @@ int tcp_recv(int sock, const char *arg)
        }
 
        while (1) {
-               ret = recv(sock, NULL, (count > 0) ? count : INT_MAX, MSG_NOSIGNAL | MSG_TRUNC);
+               max = (count > 0) ? count : INT_MAX;
+               if (max > sizeof(trash))
+                       max = sizeof(trash);
+               ret = recv(sock, trash, max, MSG_NOSIGNAL | MSG_TRUNC);
                if (ret < 0) {
                        if (errno == EINTR)
                                continue;