From 7ab3af0edc238c869827c185f997c0a99f4506b5 Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Wed, 5 Aug 2015 16:51:50 +0200
Subject: [PATCH] Fix synchronous readline "\n" handling.

Our function to read a line with a timeout handles newlines as requests
to refresh the timeout, however the code kept subtracting the buffer
size left every time a newline was received, for a bug in the loop
logic. Fixed by this commit.
---
 src/syncio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/syncio.c b/src/syncio.c
index 48e0a0b7..1d0e663c 100644
--- a/src/syncio.c
+++ b/src/syncio.c
@@ -138,6 +138,9 @@ ssize_t syncReadLine(int fd, char *ptr, ssize_t size, long long timeout) {
                 *ptr = '\0';
                 if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0';
                 return nread;
+            } else {
+                /* Read again with a fresh timeout. */
+                continue;
             }
         } else {
             *ptr++ = c;