]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: verify --size of large enough for message header
authorKarel Zak <kzak@redhat.com>
Thu, 21 Oct 2021 13:40:41 +0000 (15:40 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Oct 2021 13:40:41 +0000 (15:40 +0200)
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2011602
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/logger.c

index 599a43a1ba49bd8d7380889920a5c3ab28110ed4..23da164cd657f4198823396ba945b07b97d85f47 100644 (file)
@@ -548,8 +548,11 @@ static void syslog_rfc3164_header(struct logger_ctl *const ctl)
        } else
                hostname = xstrdup(NILVALUE);
 
-       xasprintf(&ctl->hdr, "<%d>%.15s %s %.200s%s: ",
-                ctl->pri, rfc3164_current_time(), hostname, ctl->tag, pid);
+       if ((size_t) xasprintf(&ctl->hdr, "<%d>%.15s %s %.200s%s: ",
+                        ctl->pri, rfc3164_current_time(),
+                        hostname, ctl->tag, pid) > ctl->max_message_size)
+               errx(EXIT_FAILURE, _("maximal message size is smaller than message header"));
+
 
        free(hostname);
 }
@@ -828,14 +831,15 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl)
        if (!structured)
                structured = xstrdup(NILVALUE);
 
-       xasprintf(&ctl->hdr, "<%d>1 %s %s %s %s %s %s ",
-               ctl->pri,
-               time,
-               hostname,
-               app_name,
-               procid,
-               msgid,
-               structured);
+       if ((size_t) xasprintf(&ctl->hdr, "<%d>1 %s %s %s %s %s %s ",
+                       ctl->pri,
+                       time,
+                       hostname,
+                       app_name,
+                       procid,
+                       msgid,
+                       structured) > ctl->max_message_size)
+               errx(EXIT_FAILURE, _("maximal message size is smaller than message header"));
 
        free(time);
        free(hostname);
@@ -885,8 +889,9 @@ static void syslog_local_header(struct logger_ctl *const ctl)
        else
                pid[0] = '\0';
 
-       xasprintf(&ctl->hdr, "<%d>%s %s%s: ", ctl->pri, rfc3164_current_time(),
-               ctl->tag, pid);
+       if ((size_t) xasprintf(&ctl->hdr, "<%d>%s %s%s: ", ctl->pri, rfc3164_current_time(),
+                       ctl->tag, pid) > ctl->max_message_size)
+               errx(EXIT_FAILURE, _("maximal message size is smaller than message header"));
 }
 
 static void generate_syslog_header(struct logger_ctl *const ctl)