r21740: this fixes the real cause of the large log files we had. The problem
authorAndrew Tridgell <tridge@samba.org>
Wed, 7 Mar 2007 10:00:14 +0000 (10:00 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:49:21 +0000 (14:49 -0500)
was we were not checking the result of a convert_string() call, and it
was giving -1. We then passed -1 to fwrite() on stdout, which on aix
and macosx wrote all of available memory to stdout :)

To fix this, replace non-printing chars with ? in d_printf if the
string cannot be converted
(This used to be commit d20102d363f4b9214e29296ad8ec45c8d95614b5)

source4/lib/util/dprintf.c

index 79b90ec3e1b2eac24206b887eda35d8ea1e44a74..209fb8da36691e7a9ac6fbce72fe960f272461aa 100644 (file)
@@ -30,6 +30,7 @@
 */
 
 #include "includes.h"
+#include "system/locale.h"
 
 _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0)
 {
@@ -54,6 +55,22 @@ again:
                return -1;
        }
        clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen);
+        if (clen == -1) {
+               /* the string can't be converted - do the best we can,
+                  filling in non-printing chars with '?' */
+               int i;
+               for (i=0;i<ret;i++) {
+                       if (isprint(p[i]) || isspace(p[i])) {
+                               fwrite(p+i, 1, 1, f);
+                       } else {
+                               fwrite("?", 1, 1, f);
+                       }
+               }
+               SAFE_FREE(p);
+               SAFE_FREE(p2);
+               return ret;
+        }
+
 
        if (clen >= maxlen) {
                /* it didn't fit - try a larger buffer */