mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Isaac Dunham <ibid.ag@gmail.com>
To: musl@lists.openwall.com
Cc: Isaac Dunham <ibid.ag@gmail.com>
Subject: [PATCH] fmtmsg: verify that label is in the correct format.
Date: Sat, 25 Apr 2015 09:15:35 -0700	[thread overview]
Message-ID: <1429978535-1977-1-git-send-email-ibid.ag@gmail.com> (raw)

According to POSIX, "the format is two fields separated by a colon.
The first field is up to 10 bytes, the second is up to 14 bytes."
The original implementation assumed that the application provided
a valid label.
---
 src/misc/fmtmsg.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/misc/fmtmsg.c b/src/misc/fmtmsg.c
index 69170b2..956fa5d 100644
--- a/src/misc/fmtmsg.c
+++ b/src/misc/fmtmsg.c
@@ -33,12 +33,20 @@ int fmtmsg(long classification, const char *label, int severity,
 
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
 
+	if (label) {
+		char *col = strchr(label, ':');
+		i = strlen(label);
+		if (!col || (col-label)>10 || (label+i-col)>15 ||
+		    col==label || label+i-1==col)
+			ret = MM_NOTOK;
+	}
+
 	if (severity == MM_HALT) errstring = "HALT: ";
 	else if (severity == MM_ERROR) errstring = "ERROR: ";
 	else if (severity == MM_WARNING) errstring = "WARNING: ";
 	else if (severity == MM_INFO) errstring = "INFO: ";
 
-	if (classification & MM_CONSOLE) {
+	if (!ret && classification & MM_CONSOLE) {
 		consolefd = open("/dev/console", O_WRONLY);
 		if (consolefd < 0) {
 			ret = MM_NOCON;
@@ -54,7 +62,7 @@ int fmtmsg(long classification, const char *label, int severity,
 		}
 	}
 
-	if (classification & MM_PRINT) {
+	if (ret != MM_NOTOK && classification & MM_PRINT) {
 		while (cmsg && cmsg[0]) {
 			for(i=0; msgs[i]; i++) {
 				if (!_strcolcmp(msgs[i], cmsg)) break;
-- 
2.3.6



             reply	other threads:[~2015-04-25 16:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-25 16:15 Isaac Dunham [this message]
2015-04-25 17:14 ` Rich Felker
2015-04-25 18:19   ` Isaac Dunham

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=1429978535-1977-1-git-send-email-ibid.ag@gmail.com \
    --to=ibid.ag@gmail.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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