]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: fix buffer overflow when read stdin
authorKarel Zak <kzak@redhat.com>
Wed, 10 Sep 2025 08:31:23 +0000 (10:31 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Sep 2025 07:47:47 +0000 (09:47 +0200)
$ perl -e 'print "<" . "0"x10240' | logger --prio-prefix
Segmentation fault (core dumped)

Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit f9cdc91be0442b887e4a636fbb75f027f0267a84)

misc-utils/logger.c

index c8eff50701c825ecdd2e94a9bccc0fec53004d17..f332a7d2716d0249313d307a0cf53c2812310538 100644 (file)
@@ -1025,7 +1025,9 @@ static void logger_stdin(struct logger_ctl *ctl)
                if (ctl->prio_prefix && c == '<') {
                        pri = 0;
                        buf[i++] = c;
-                       while (isdigit(c = getchar()) && pri <= 191) {
+                       while (i < ctl->max_message_size
+                              && isdigit(c = getchar()) && pri <= 191) {
+
                                buf[i++] = c;
                                pri = pri * 10 + c - '0';
                        }