[dovecot-cvs] dovecot/src/lib failures.c,1.22,1.23 printf-upper-bound.c,1.3,1.4 printf-upper-bound.h,1.1,1.2 str.c,1.10,1.11 strfuncs.c,1.31,1.32

cras at procontrol.fi cras at procontrol.fi
Mon Sep 8 05:29:09 EEST 2003


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv4411/lib

Modified Files:
	failures.c printf-upper-bound.c printf-upper-bound.h str.c 
	strfuncs.c 
Log Message:
Call printf_string_fix_format() only when printf_string_upper_bound() sees
%m.



Index: failures.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/failures.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- failures.c	26 Aug 2003 21:18:16 -0000	1.22
+++ failures.c	8 Sep 2003 01:29:07 -0000	1.23
@@ -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--;

Index: printf-upper-bound.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/printf-upper-bound.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- printf-upper-bound.c	8 Sep 2003 01:14:17 -0000	1.3
+++ printf-upper-bound.c	8 Sep 2003 01:29:07 -0000	1.4
@@ -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;
 }

Index: printf-upper-bound.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/printf-upper-bound.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- printf-upper-bound.h	22 Dec 2002 07:06:16 -0000	1.1
+++ printf-upper-bound.h	8 Sep 2003 01:29:07 -0000	1.2
@@ -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

Index: str.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/str.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- str.c	26 Aug 2003 21:18:16 -0000	1.10
+++ str.c	8 Sep 2003 01:29:07 -0000	1.11
@@ -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

Index: strfuncs.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/strfuncs.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- strfuncs.c	26 Aug 2003 21:18:16 -0000	1.31
+++ strfuncs.c	8 Sep 2003 01:29:07 -0000	1.32
@@ -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



More information about the dovecot-cvs mailing list