]> granicus.if.org Git - libtirpc/commitdiff
write_vc: fix write retry loop for nonblocking mode libtirpc-0-2-6-rc1
authorBodo Stroesser <bstroesser@ts.fujitsu.com>
Thu, 6 Nov 2014 18:26:00 +0000 (13:26 -0500)
committerSteve Dickson <steved@redhat.com>
Thu, 6 Nov 2014 18:26:49 +0000 (13:26 -0500)
This is a simple fix for the write retry loop that is used on
non-blocking connections if write() failed with -EAGAIN.

Additionally it removes a redundant if () {}

Erroneously at each cycle of the loop the length of the data
to send is incremented and the buffer pointer is decremented.
Thus, it might happen that:
* the application crashes
* data from the memory before the buffer is sent

Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
src/svc_vc.c

index 4c70de84e23660334bdf65d5314041fa0265d3a7..4d3ea51e7a0ab73aefd71647aeabbcbc3d91b278 100644 (file)
@@ -559,20 +559,19 @@ write_vc(xprtp, buf, len)
                                cd->strm_stat = XPRT_DIED;
                                return (-1);
                        }
-                       if (cd->nonblock && i != cnt) {
-                               /*
-                                * For non-blocking connections, do not
-                                * take more than 2 seconds writing the
-                                * data out.
-                                *
-                                * XXX 2 is an arbitrary amount.
-                                */
-                               gettimeofday(&tv1, NULL);
-                               if (tv1.tv_sec - tv0.tv_sec >= 2) {
-                                       cd->strm_stat = XPRT_DIED;
-                                       return (-1);
-                               }
+                       /*
+                        * For non-blocking connections, do not
+                        * take more than 2 seconds writing the
+                        * data out.
+                        *
+                        * XXX 2 is an arbitrary amount.
+                        */
+                       gettimeofday(&tv1, NULL);
+                       if (tv1.tv_sec - tv0.tv_sec >= 2) {
+                               cd->strm_stat = XPRT_DIED;
+                               return (-1);
                        }
+                       i = 0; /* Don't change buf and cnt */
                }
        }