NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/39912: logger(1) output is wrong due to incorrect usage of syslogp(3)



>Number:         39912
>Category:       bin
>Synopsis:       logger(1) output is wrong due to incorrect usage of syslogp(3)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 13 12:55:01 +0000 2008
>Originator:     M. Levinson
>Release:        NetBSD 5.99.01 from 2008-11-13
>Organization:
>Environment:
     $NetBSD: logger.c,v 1.12 2008/10/31 20:53:46 christos Exp $
Architecture: x86_64
Machine: amd64
>Description:
        In src/usr.bin/logger/logger.c, syslogp(3) is called incorrectly (its
        arguments are in the wrong order). As a result the MSGID and SD
        fields appear after the message instead of before it, and syslogd(8)
        parses the line incorrectly.

>How-To-Repeat:
        The following command:
                                logger -m MSGID -t TESTING -s This is a test.
        produces this output:
                                TESTING - This is a test. MSGID -

        With the patch below, its output is:
                                TESTING - MSGID - This is a test.

>Fix:

--- src/usr.bin/logger/logger.c 2008/11/13 12:37:57
+++ src/usr.bin/logger/logger.c 2008/11/13 12:39:35
@@ -119,11 +119,11 @@
                for (p = buf, endp = buf + sizeof(buf) - 2; *argv != NULL;) {
                        len = strlen(*argv);
                        if (p + len > endp && p > buf) {
-                               syslogp(pri, "%s", msgid, sd, buf);
+                               syslogp(pri, msgid, sd, "%s", buf);
                                p = buf;
                        }
                        if (len > sizeof(buf) - 1)
-                               syslogp(pri, "%s", msgid, sd, *argv++);
+                               syslogp(pri, msgid, sd, "%s", *argv++);
                        else {
                                if (p != buf)
                                        *p++ = ' ';
@@ -132,13 +132,13 @@
                        }
                }
                if (p != buf)
-                       syslogp(pri, "%s", msgid, sd, buf);
+                       syslogp(pri, msgid, sd, "%s", buf);
        } else  /* TODO: allow syslog-protocol messages from file/stdin
                 *       but that will require parsing the line to split
                 *       it into three fields.
                 */
                while (fgets(buf, sizeof(buf), stdin) != NULL)
-                       syslogp(pri, "%s", msgid, sd, buf);
+                       syslogp(pri, msgid, sd, "%s", buf);
 
        exit(EXIT_SUCCESS);
        /* NOTREACHED */



Home | Main Index | Thread Index | Old Index