Mercurial > dovecot > core-2.2
changeset 1763:32bfcbe2a006 HEAD
Call printf_string_fix_format() only when printf_string_upper_bound() sees
%m.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 08 Sep 2003 04:29:07 +0300 |
parents | 520e3a0496db |
children | fbb28b07c60f |
files | src/lib/failures.c src/lib/printf-upper-bound.c src/lib/printf-upper-bound.h src/lib/str.c src/lib/strfuncs.c |
diffstat | 5 files changed, 21 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/failures.c Mon Sep 08 04:14:17 2003 +0300 +++ b/src/lib/failures.c Mon Sep 08 04:29:07 2003 +0300 @@ -84,20 +84,17 @@ t_push(); if (recursed == 2) { - /* write without fixing format, that probably killed us - last time. */ + /* printf_string_upper_bound() probably killed us last time, + just write the format now. */ - /* make sure there's no %n in there */ - (void)printf_string_upper_bound(format, args); - vfprintf(f, format, args2); - fputs(" - recursed!", f); + fputs("recursed: ", f); + fputs(format, f); } else { write_prefix(f); fputs(prefix, f); - format = printf_string_fix_format(format); - /* make sure there's no %n in there */ - (void)printf_string_upper_bound(format, args); + /* make sure there's no %n in there and fix %m */ + (void)printf_string_upper_bound(&format, args); vfprintf(f, format, args2); } @@ -268,7 +265,7 @@ /* make sure there's no %n in there */ VA_COPY(args2, args); - (void)printf_string_upper_bound(format, args); + (void)printf_string_upper_bound(&format, args); vsyslog(level, format, args2); recursed--;
--- a/src/lib/printf-upper-bound.c Mon Sep 08 04:14:17 2003 +0300 +++ b/src/lib/printf-upper-bound.c Mon Sep 08 04:29:07 2003 +0300 @@ -66,9 +66,11 @@ # define HONOUR_LONGS 0 #endif -size_t printf_string_upper_bound(const char *format, va_list args) +size_t printf_string_upper_bound(const char **format_p, va_list args) { + const char *format = *format_p; size_t len = 1; + int fix_format = FALSE; if (!format) return len; @@ -296,10 +298,9 @@ (void) va_arg (args, void*); break; case 'm': - /* normally we shouldn't even get here, but we could be just - checking the format string is valid before giving the - format to vsyslog(). */ + /* %m, replace it with strerror() later */ conv_len += strlen(strerror(errno)) + 256; + fix_format = TRUE; break; /* handle invalid cases @@ -325,5 +326,7 @@ } /* else (c == '%') */ } /* while (*format) */ + if (fix_format) + *format_p = printf_string_fix_format(*format_p); return len; }
--- a/src/lib/printf-upper-bound.h Mon Sep 08 04:14:17 2003 +0300 +++ b/src/lib/printf-upper-bound.h Mon Sep 08 04:29:07 2003 +0300 @@ -2,7 +2,9 @@ #define __PRINTF_UPPER_BOUND_H /* Returns the maximum length of given format string when expanded. - If the format is invalid, i_fatal() is called. */ -size_t printf_string_upper_bound(const char *format, va_list args); + If the format is invalid, i_fatal() is called. + + If format contains %m, it's replaced with the real error message. */ +size_t printf_string_upper_bound(const char **format, va_list args); #endif
--- a/src/lib/str.c Mon Sep 08 04:14:17 2003 +0300 +++ b/src/lib/str.c Mon Sep 08 04:29:07 2003 +0300 @@ -119,9 +119,7 @@ len = buffer_get_used_size(str); - fmt = printf_string_fix_format(fmt); - append_len = printf_string_upper_bound(fmt, args); - + append_len = printf_string_upper_bound(&fmt, args); buf = buffer_append_space_unsafe(str, append_len); #ifdef HAVE_VSNPRINTF
--- a/src/lib/strfuncs.c Mon Sep 08 04:14:17 2003 +0300 +++ b/src/lib/strfuncs.c Mon Sep 08 04:29:07 2003 +0300 @@ -85,8 +85,7 @@ va_start(args, format); VA_COPY(args2, args); - format = printf_string_fix_format(format); - len = printf_string_upper_bound(format, args); + len = printf_string_upper_bound(&format, args); i_assert(len >= 0); @@ -203,9 +202,7 @@ VA_COPY(args2, args); - format = printf_string_fix_format(format); - - len = printf_string_upper_bound(format, args); + len = printf_string_upper_bound(&format, args); ret = p_malloc(pool, len); #ifdef HAVE_VSNPRINTF