OSDN Git Service

Jean writes:
authorEric Andersen <andersen@codepoet.org>
Tue, 11 Jan 2005 11:31:55 +0000 (11:31 -0000)
committerEric Andersen <andersen@codepoet.org>
Tue, 11 Jan 2005 11:31:55 +0000 (11:31 -0000)
Hello,

under some circumstances the following small example prints lots of
garbage onto the console and into the syslog:

#include <syslog.h>
int main ()
{
        openlog("foo", LOG_CONS|LOG_NDELAY|LOG_PID|LOG_PERROR, LOG_DAEMON);
        syslog (LOG_WARNING, "mlock: %m");
        return 1;
}

The reason is, that sprintf returns with -1 and vsyslog dumps the
complete buffer onto stderr and the syslogd socket. The following
patch would fix the problem:

libc/misc/syslog/syslog.c

index 250cb6d..e39e63a 100644 (file)
@@ -206,7 +206,15 @@ vsyslog( int pri, const char *fmt, va_list ap )
                memmove(head_end + sizeof(truncate_msg), head_end,
                        end - head_end - sizeof(truncate_msg));
                memcpy(head_end, truncate_msg, sizeof(truncate_msg));
-               p = end - 1;
+               if (p < head_end) {
+                       while (p < end && *p) {
+                               p++;
+                       }
+               }
+               else {
+                       p = end - 1;
+               }
+
        }
        last_chr = p;