[PATCH] Check realloc return value in udev collect utility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

In extras/collect/collect.c a recent commit introduced reallocation of a
buffer. Though the return value of realloc() is not checked. The
attached patch fixes this and also changes the data type of bufsize to
size_t which makes more sense and silences a GCC warning about comparing
unsigned and signed integers.

Cheers, Tobias

diff --git a/extras/collect/collect.c b/extras/collect/collect.c
index feb0e75..9fb6737 100644
--- a/extras/collect/collect.c
+++ b/extras/collect/collect.c
@@ -53,7 +53,7 @@ static LIST_HEAD(bunch);
 static int debug;
 
 /* This can increase dynamically */
-static int bufsize = BUFSIZE;
+static size_t bufsize = BUFSIZE;
 
 static void sig_alrm(int signo)
 {
@@ -272,8 +272,15 @@ static int missing(int fd)
 			ret++;
 		} else {
 			while (strlen(him->name)+1 >= bufsize) {
+				char *tmpbuf;
+
 				bufsize = bufsize << 1;
-				buf = realloc(buf, bufsize);
+				tmpbuf = realloc(buf, bufsize);
+				if (!tmpbuf) {
+					free(buf);
+					return -1;
+				}
+				buf = tmpbuf;
 			}
 			snprintf(buf, strlen(him->name)+2, "%s ", him->name);
 			write(fd, buf, strlen(buf));
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux