Try to fix the iconv crash in bug 11338. master
authorWayne Davison <wayned@samba.org>
Sat, 16 Mar 2019 18:49:53 +0000 (11:49 -0700)
committerWayne Davison <wayned@samba.org>
Sat, 16 Mar 2019 18:51:49 +0000 (11:51 -0700)
Applying Michal Ruprich's suggested patch for the rwrite() function that
should hopefully help with a bug that I couldn't reproduce.

log.c

diff --git a/log.c b/log.c
index 21bcdfd..a86edd7 100644 (file)
--- a/log.c
+++ b/log.c
@@ -378,10 +378,13 @@ output_msg:
                                filtered_fwrite(f, convbuf, outbuf.len, 0);
                                outbuf.len = 0;
                        }
-                       if (!ierrno || ierrno == E2BIG)
-                               continue;
-                       fprintf(f, "\\#%03o", CVAL(inbuf.buf, inbuf.pos++));
-                       inbuf.len--;
+                       /* Log one byte of illegal/incomplete sequence and continue with
+                        * the next character. Check that the buffer is non-empty for the
+                        * sake of robustness. */
+                       if ((ierrno == EILSEQ || ierrno == EINVAL) && inbuf.len) {
+                               fprintf(f, "\\#%03o", CVAL(inbuf.buf, inbuf.pos++));
+                               inbuf.len--;
+                       }
                }
        } else
 #endif