%m.
--HG--
branch : HEAD
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);
}
/* 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--;
# 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;
(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
} /* else (c == '%') */
} /* while (*format) */
+ if (fix_format)
+ *format_p = printf_string_fix_format(*format_p);
return len;
}
#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
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
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);
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