From b406b8708fef5ff51e684794b5df4fea728b0058 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 22 Aug 2018 05:20:32 +0200 Subject: [PATCH] BUG/MEDIUM: connection: don't store recv() result into trash.data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cyril Bonté discovered that the proxy protocol randomly fails since commit 843b7cb ("MEDIUM: chunks: make the chunk struct's fields match the buffer struct"). This is because we used to store recv()'s return code into trash.data which is now unsigned, so it never compares as negative against 0. Let's clean this up and test the result itself without storing it first. No backport is needed. --- src/connection.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/connection.c b/src/connection.c index ee80e616f..b3ef56eba 100644 --- a/src/connection.c +++ b/src/connection.c @@ -424,6 +424,7 @@ int conn_recv_proxy(struct connection *conn, int flag) const char v2sig[] = PP2_SIGNATURE; int tlv_length = 0; int tlv_offset = 0; + int ret; /* we might have been called just after an asynchronous shutr */ if (conn->flags & CO_FL_SOCK_RD_SH) @@ -436,9 +437,8 @@ int conn_recv_proxy(struct connection *conn, int flag) return 0; do { - trash.data = recv(conn->handle.fd, trash.area, trash.size, - MSG_PEEK); - if (trash.data < 0) { + ret = recv(conn->handle.fd, trash.area, trash.size, MSG_PEEK); + if (ret < 0) { if (errno == EINTR) continue; if (errno == EAGAIN) { @@ -447,6 +447,7 @@ int conn_recv_proxy(struct connection *conn, int flag) } goto recv_abort; } + trash.data = ret; } while (0); if (!trash.data) { @@ -738,6 +739,7 @@ int conn_recv_netscaler_cip(struct connection *conn, int flag) char *line; uint32_t hdr_len; uint8_t ip_v; + int ret; /* we might have been called just after an asynchronous shutr */ if (conn->flags & CO_FL_SOCK_RD_SH) @@ -750,9 +752,8 @@ int conn_recv_netscaler_cip(struct connection *conn, int flag) return 0; do { - trash.data = recv(conn->handle.fd, trash.area, trash.size, - MSG_PEEK); - if (trash.data < 0) { + ret = recv(conn->handle.fd, trash.area, trash.size, MSG_PEEK); + if (ret < 0) { if (errno == EINTR) continue; if (errno == EAGAIN) { @@ -761,6 +762,7 @@ int conn_recv_netscaler_cip(struct connection *conn, int flag) } goto recv_abort; } + trash.data = ret; } while (0); if (!trash.data) {