From 0e6af5a1500ab03eb470bb259c27cee2e0b9c29b Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Mon, 22 May 2000 22:09:25 +0000 Subject: [PATCH] (vsyslog): calculate length of new format string correctly git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8283 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/vsyslog.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/roken/vsyslog.c b/lib/roken/vsyslog.c index 6b7da5d6c..2ba1eedc8 100644 --- a/lib/roken/vsyslog.c +++ b/lib/roken/vsyslog.c @@ -44,12 +44,23 @@ RCSID("$Id$"); #include "roken.h" +/* + * the theory behind this is that we might be trying to call vsyslog + * when there's no memory left, and we should try to be as useful as + * possible. And the format string should say something about what's + * failing. + */ + static void simple_vsyslog(int pri, const char *fmt, va_list ap) { syslog (pri, "%s", fmt); } +/* + * do like syslog but with a `va_list' + */ + void vsyslog(int pri, const char *fmt, va_list ap) { @@ -57,10 +68,11 @@ vsyslog(int pri, const char *fmt, va_list ap) const char *p; char *p2; int saved_errno = errno; - int fmtlen = strlen (fmt); + int fmt_len = strlen (fmt); + int fmt2_len = fmt_len; char *buf; - fmt2 = malloc (fmtlen + 1); + fmt2 = malloc (fmt_len + 1); if (fmt2 == NULL) { simple_vsyslog (pri, fmt, ap); return; @@ -74,7 +86,8 @@ vsyslog(int pri, const char *fmt, va_list ap) int pos; pos = p2 - fmt2; - tmp = realloc (fmt2, fmtlen + 1 + e_len - 2); + fmt2_len += e_len - 2; + tmp = realloc (fmt2, fmt2_len + 1); if (tmp == NULL) { free (fmt2); simple_vsyslog (pri, fmt, ap);