csomh / rpms / rsync

Forked from rpms/rsync 3 years ago
Clone
3b0c2c
diff --git a/io.c b/io.c
3b0c2c
index 999c34e5..ceff3784 100644
3b0c2c
--- a/io.c
3b0c2c
+++ b/io.c
3b0c2c
@@ -954,8 +954,17 @@ int send_msg(enum msgcode code, const char *buf, size_t len, int convert)
3b0c2c
 	} else
3b0c2c
 #endif
3b0c2c
 		needed = len + 4 + 3;
3b0c2c
-	if (iobuf.msg.len + needed > iobuf.msg.size)
3b0c2c
-		perform_io(needed, PIO_NEED_MSGROOM);
3b0c2c
+	if (iobuf.msg.len + needed > iobuf.msg.size) {
3b0c2c
+		if (!am_receiver)
3b0c2c
+			perform_io(needed, PIO_NEED_MSGROOM);
3b0c2c
+		else { /* We allow the receiver to increase their iobuf.msg size to avoid a deadlock. */
3b0c2c
+			size_t old_size = iobuf.msg.size;
3b0c2c
+			restore_iobuf_size(&iobuf.msg);
3b0c2c
+			realloc_xbuf(&iobuf.msg, iobuf.msg.size * 2);
3b0c2c
+			if (iobuf.msg.pos + iobuf.msg.len > old_size)
3b0c2c
+				memcpy(iobuf.msg.buf + old_size, iobuf.msg.buf, iobuf.msg.pos + iobuf.msg.len - old_size);
3b0c2c
+		}
3b0c2c
+	}
3b0c2c
 
3b0c2c
 	pos = iobuf.msg.pos + iobuf.msg.len; /* Must be set after any flushing. */
3b0c2c
 	if (pos >= iobuf.msg.size)
3b0c2c
@@ -1176,7 +1185,7 @@ int read_line(int fd, char *buf, size_t bufsiz, int flags)
3b0c2c
 
3b0c2c
 #ifdef ICONV_OPTION
3b0c2c
 	if (flags & RL_CONVERT && iconv_buf.size < bufsiz)
3b0c2c
-		realloc_xbuf(&iconv_buf, bufsiz + 1024);
3b0c2c
+		realloc_xbuf(&iconv_buf, ROUND_UP_1024(bufsiz) + 1024);
3b0c2c
 #endif
3b0c2c
 
3b0c2c
   start: