Skip to contentSkip to conversation

LVM2/daemons/common daemon-shared.c

PATCH [email protected] 1 participant 1 message Jan 16, 2012

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall at sourceware.org 2012-01-16 05:09:16

Modified files:
daemons/common : daemon-shared.c

Log message:
Fix a boundary condition in read_buffer in daemon-shared.c.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/common/daemon-shared.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8

daemons/common/daemon-shared.c +6 -7
@@ -30,20 +30,19 @@
 		if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK)
 			goto fail;
 
+		if ((!strncmp((*buffer) + bytes - 4, "\n##\n", 4))) {
+			*(*buffer + bytes - 4) = 0;
+			break; /* success, we have the full message now */
+		}
+
 		if (bytes == buffersize) {
 			buffersize += 1024;
 			if (!(new = realloc(*buffer, buffersize + 1)))
 				goto fail;
 
 			*buffer = new;
-		} else {
-			(*buffer)[bytes] = 0;
-			if ((end = strstr((*buffer) + bytes - 4, "\n##\n"))) {
-				*end = 0;
-				break; /* success, we have the full message now */
-			}
-			/* TODO call select here if we encountered EAGAIN/EWOULDBLOCK */
 		}
+		/* TODO call select here if we encountered EAGAIN/EWOULDBLOCK */
 	}
 	return 1;
 fail: