]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
syslog: Remove extra whitespace between timestamp and message (BZ#29544)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 5 Sep 2022 12:34:39 +0000 (09:34 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 5 Sep 2022 12:34:39 +0000 (09:34 -0300)
The rfc3164 clear states that a single space character must follow
the timestamp field.

Checked on x86_64-linux-gnu.

misc/syslog.c
misc/tst-syslog.c

index b88f66c8359b17aa48f4900ab7d3d41eb4159c2e..f67d4b58a448cabdf63f629f72a9df6e009286cf 100644 (file)
@@ -167,7 +167,7 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap,
                  _nl_C_locobj_ptr);
 
 #define SYSLOG_HEADER(__pri, __timestamp, __msgoff, pid) \
-  "<%d>%s %n%s%s%.0d%s: ",                               \
+  "<%d>%s%n%s%s%.0d%s: ",                                \
   __pri, __timestamp, __msgoff,                          \
   LogTag == NULL ? __progname : LogTag,                  \
   "[" + (pid == 0), pid, "]" + (pid == 0)
index 1d332ece537d56987ea63fceb7a9599ccc675493..3560b518a25d1ee1bb96f19db32a7d9ecb6ba091 100644 (file)
@@ -275,16 +275,19 @@ parse_syslog_msg (const char *msg)
 {
   struct msg_t r = { .pid = -1 };
   int number;
+  int wsb, wsa;
 
 #define STRINPUT(size)  XSTRINPUT(size)
 #define XSTRINPUT(size) "%" # size "s"
 
   /* The message in the form:
-     <179>Apr  8 14:51:19  tst-syslog: message 176 3  */
-  int n = sscanf (msg, "<%3d>%*s %*d %*d:%*d:%*d " STRINPUT(IDENT_LENGTH)
+     <179>Apr  8 14:51:19 tst-syslog: message 176 3  */
+  int n = sscanf (msg, "<%3d>%*s %*d %*d:%*d:%*d%n %n" STRINPUT(IDENT_LENGTH)
                       " " STRINPUT(MSG_LENGTH) " %*d %*d",
-                  &number, r.ident, r.msg);
+                  &number, &wsb, &wsa, r.ident, r.msg);
   TEST_COMPARE (n, 3);
+  /* It should only one space between timestamp and message.  */
+  TEST_COMPARE (wsa - wsb, 1);
 
   r.facility = number & LOG_FACMASK;
   r.priority = number & LOG_PRIMASK;