From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: Weird bug in syslog
Date: Wed, 20 Mar 2013 19:55:31 +0100 [thread overview]
Message-ID: <20130320185531.GM19010@port70.net> (raw)
In-Reply-To: <20130320124125.GL19010@port70.net>
[-- Attachment #1: Type: text/plain, Size: 82 bytes --]
syslog fix
proper bounds checks, size_t len and no unlock (wrapper should do it)
[-- Attachment #2: musl-syslog.diff --]
[-- Type: text/x-diff, Size: 1281 bytes --]
diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 8de34f8..ef8dcfb 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -8,6 +8,7 @@
#include <signal.h>
#include <string.h>
#include <pthread.h>
+#include <limits.h>
#include "libc.h"
static int lock[2];
@@ -71,14 +72,11 @@ static void _vsyslog(int priority, const char *message, va_list ap)
struct tm tm;
char buf[256];
int pid;
- int l, l2;
+ size_t l, l2;
if (log_fd < 0) {
__openlog(log_ident, log_opt | LOG_NDELAY, log_facility);
- if (log_fd < 0) {
- UNLOCK(lock);
- return;
- }
+ if (log_fd < 0) return;
}
now = time(NULL);
@@ -90,14 +88,13 @@ static void _vsyslog(int priority, const char *message, va_list ap)
priority, timebuf,
log_ident ? log_ident : "",
"["+!pid, pid, "]"+!pid);
+ if (l >= sizeof buf) l = sizeof buf - 1;
l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
- if (l2 >= 0) {
- l += l2;
- if (buf[l-1] != '\n') buf[l++] = '\n';
- sendto(log_fd, buf, l, 0, (void *)&log_addr, 11);
- }
-
- UNLOCK(lock);
+ if (l2 > INT_MAX) return;
+ l += l2;
+ if (l >= sizeof buf) l = sizeof buf - 1;
+ if (buf[l-1] != '\n') buf[l++] = '\n';
+ sendto(log_fd, buf, l, 0, (void *)&log_addr, 11);
}
void __vsyslog(int priority, const char *message, va_list ap)
next prev parent reply other threads:[~2013-03-20 18:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-19 19:32 William Haddon
2013-03-20 12:41 ` Szabolcs Nagy
2013-03-20 18:55 ` Szabolcs Nagy [this message]
2013-03-20 19:02 ` Rich Felker
2013-03-21 1:43 ` William Haddon
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=20130320185531.GM19010@port70.net \
--to=nsz@port70.net \
--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).