linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@distanz.ch>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] Check realloc return value in udev collect utility
Date: Tue, 17 Jun 2008 22:47:33 +0000	[thread overview]
Message-ID: <20080617224733.GA23091@distanz.ch> (raw)

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));

             reply	other threads:[~2008-06-17 22:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-17 22:47 Tobias Klauser [this message]
2008-06-18  8:15 ` [PATCH] Check realloc return value in udev collect utility Kay Sievers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080617224733.GA23091@distanz.ch \
    --to=tklauser@distanz.ch \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).