12a457
From cb7e11f4503c1fe08d821d9d92e34601c542bd83 Mon Sep 17 00:00:00 2001
12a457
From: Xavier Hernandez <xhernandez@datalab.es>
12a457
Date: Mon, 9 May 2016 12:50:39 +0200
12a457
Subject: [PATCH 152/158] socket: Fix incorrect handling of partial reads
12a457
12a457
The usage of function local variables in the protocol state
12a457
machine caused an incorrect behaviour when a partial read
12a457
from the socket forced the function to return and restart
12a457
later when more data was available. At this point the local
12a457
variables contained incorrect data.
12a457
12a457
Change-Id: I4db1f4ef5c46a3d2d7f7c5328e906188c3af49e6
12a457
BUG: 1334985
12a457
Signed-off-by: Xavier Hernandez <xhernandez@datalab.es>
12a457
Reviewed-on: http://review.gluster.org/14270
12a457
Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
12a457
Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
Tested-by: Raghavendra G <rgowdapp@redhat.com>
12a457
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/74342
12a457
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
12a457
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
12a457
---
12a457
 rpc/rpc-transport/socket/src/socket.c |    8 +++++---
12a457
 1 files changed, 5 insertions(+), 3 deletions(-)
12a457
12a457
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
12a457
index 43caa70..b857198 100644
12a457
--- a/rpc/rpc-transport/socket/src/socket.c
12a457
+++ b/rpc/rpc-transport/socket/src/socket.c
12a457
@@ -1649,7 +1649,6 @@ __socket_read_accepted_successful_reply (rpc_transport_t *this)
12a457
         gfs3_read_rsp     read_rsp          = {0, };
12a457
         ssize_t           size              = 0;
12a457
         ssize_t           default_read_size = 0;
12a457
-        char             *proghdr_buf       = NULL;
12a457
         XDR               xdr;
12a457
         struct gf_sock_incoming      *in         = NULL;
12a457
         struct gf_sock_incoming_frag *frag       = NULL;
12a457
@@ -1669,7 +1668,9 @@ __socket_read_accepted_successful_reply (rpc_transport_t *this)
12a457
                 default_read_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_read_rsp,
12a457
                                                 &read_rsp);
12a457
 
12a457
-                proghdr_buf = frag->fragcurrent;
12a457
+                /* We need to store the current base address because we will
12a457
+                 * need it after a partial read. */
12a457
+                in->proghdr_base_addr = frag->fragcurrent;
12a457
 
12a457
                 __socket_proto_init_pending (priv, default_read_size);
12a457
 
12a457
@@ -1682,7 +1683,8 @@ __socket_read_accepted_successful_reply (rpc_transport_t *this)
12a457
                 __socket_proto_read (priv, ret);
12a457
 
12a457
                 /* there can be 'xdata' in read response, figure it out */
12a457
-                xdrmem_create (&xdr, proghdr_buf, default_read_size,
12a457
+                default_read_size = frag->fragcurrent - in->proghdr_base_addr;
12a457
+                xdrmem_create (&xdr, in->proghdr_base_addr, default_read_size,
12a457
                                XDR_DECODE);
12a457
 
12a457
                 /* This will fail if there is xdata sent from server, if not,
12a457
-- 
12a457
1.7.1
12a457