trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: trinity@vger.kernel.org
Subject: [PATCH] Fix buffer overflow in output() when pid slot is not found
Date: Fri, 23 May 2014 19:09:03 +1000	[thread overview]
Message-ID: <1400836143-22355-1-git-send-email-mpe@ellerman.id.au> (raw)

In output() we sprintf() the result of find_pid_slot(). We print the pid
slot to the buffer with %u and have space for two digits of pid slot.
find_pid_slot() potentially returns PIDSLOT_NOT_FOUND (-1), which when
printed with %u is 4294967295 - ten digits.

Fix it two ways, use snprintf() - truncated output is better than a
buffer overflow. And allocate more space in the buffer, 32 bytes is a
nice round size, and gives us space for everything.
---
 log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/log.c b/log.c
index 91b4f63..584901c 100644
--- a/log.c
+++ b/log.c
@@ -291,7 +291,7 @@ void output(unsigned char level, const char *fmt, ...)
 	char watchdog_prefix[]="[watchdog]";
 	char init_prefix[]="[init]";
 	char main_prefix[]="[main]";
-	char child_prefix[]="[childNN:1234567890]";
+	char child_prefix[32];
 
 	if (logging == FALSE && level >= quiet_level)
 		return;
@@ -311,7 +311,7 @@ void output(unsigned char level, const char *fmt, ...)
 		unsigned int slot;
 
 		slot = find_pid_slot(pid);
-		sprintf(child_prefix, "[child%u:%u]", slot, pid);
+		snprintf(child_prefix, sizeof(child_prefix), "[child%u:%u]", slot, pid);
 		prefix = child_prefix;
 	}
 
-- 
1.9.1

             reply	other threads:[~2014-05-23  9:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-23  9:09 Michael Ellerman [this message]
2014-05-24  0:51 ` [PATCH] Fix buffer overflow in output() when pid slot is not found Dave Jones
2014-05-26  5:11   ` Michael Ellerman

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=1400836143-22355-1-git-send-email-mpe@ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=trinity@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 read-only IMAP folder(s) and NNTP newsgroup(s).