|
Message-Id: <1429978535-1977-1-git-send-email-ibid.ag@gmail.com> Date: Sat, 25 Apr 2015 09:15:35 -0700 From: Isaac Dunham <ibid.ag@...il.com> To: musl@...ts.openwall.com Cc: Isaac Dunham <ibid.ag@...il.com> Subject: [PATCH] fmtmsg: verify that label is in the correct format. 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.