|
|
673c78 |
From 199c328686aac174b0535619e5cea8450016e827 Mon Sep 17 00:00:00 2001
|
|
|
673c78 |
From: Karel Zak <kzak@redhat.com>
|
|
|
673c78 |
Date: Thu, 21 Oct 2021 18:47:40 +0200
|
|
|
673c78 |
Subject: logger: fix --size use for stdin
|
|
|
673c78 |
MIME-Version: 1.0
|
|
|
673c78 |
Content-Type: text/plain; charset=UTF-8
|
|
|
673c78 |
Content-Transfer-Encoding: 8bit
|
|
|
673c78 |
|
|
|
673c78 |
The stdin version counts log header into the message size, but
|
|
|
673c78 |
for example when it reads message from argv[] it counts only message
|
|
|
673c78 |
itself.
|
|
|
673c78 |
|
|
|
673c78 |
$ logger --stderr --size 3 "abcd"
|
|
|
673c78 |
<13>Oct 21 18:48:29 kzak: abc
|
|
|
673c78 |
|
|
|
673c78 |
$ echo "abcd" | logger --stderr --size 3
|
|
|
673c78 |
logger: cannot allocate 18446744073709551597 bytes: Cannot allocate memory
|
|
|
673c78 |
|
|
|
673c78 |
Upstream: http://github.com/util-linux/util-linux/commit/58e4ee082bca100034791a4a74481f263bb30a25
|
|
|
673c78 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2033622
|
|
|
673c78 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
673c78 |
---
|
|
|
673c78 |
misc-utils/logger.c | 9 +++------
|
|
|
673c78 |
1 file changed, 3 insertions(+), 6 deletions(-)
|
|
|
673c78 |
|
|
|
673c78 |
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
|
|
|
673c78 |
index 5b122de79..43284caeb 100644
|
|
|
673c78 |
--- a/misc-utils/logger.c
|
|
|
673c78 |
+++ b/misc-utils/logger.c
|
|
|
673c78 |
@@ -976,8 +976,7 @@ static void logger_stdin(struct logger_ctl *ctl)
|
|
|
673c78 |
int has_header = 1;
|
|
|
673c78 |
int default_priority = ctl->pri;
|
|
|
673c78 |
int last_pri = default_priority;
|
|
|
673c78 |
- size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
|
|
|
673c78 |
- char *const buf = xmalloc(max_usrmsg_size + 2 + 2);
|
|
|
673c78 |
+ char *buf = xmalloc(ctl->max_message_size + 2 + 2);
|
|
|
673c78 |
int pri;
|
|
|
673c78 |
int c;
|
|
|
673c78 |
size_t i;
|
|
|
673c78 |
@@ -1004,16 +1003,14 @@ static void logger_stdin(struct logger_ctl *ctl)
|
|
|
673c78 |
ctl->pri = default_priority;
|
|
|
673c78 |
|
|
|
673c78 |
if (ctl->pri != last_pri) {
|
|
|
673c78 |
- has_header = 0;
|
|
|
673c78 |
- max_usrmsg_size =
|
|
|
673c78 |
- ctl->max_message_size - strlen(ctl->hdr);
|
|
|
673c78 |
+ generate_syslog_header(ctl);
|
|
|
673c78 |
last_pri = ctl->pri;
|
|
|
673c78 |
}
|
|
|
673c78 |
if (c != EOF && c != '\n')
|
|
|
673c78 |
c = getchar();
|
|
|
673c78 |
}
|
|
|
673c78 |
|
|
|
673c78 |
- while (c != EOF && c != '\n' && i < max_usrmsg_size) {
|
|
|
673c78 |
+ while (c != EOF && c != '\n' && i < ctl->max_message_size) {
|
|
|
673c78 |
buf[i++] = c;
|
|
|
673c78 |
c = getchar();
|
|
|
673c78 |
}
|
|
|
673c78 |
--
|
|
|
673c78 |
2.34.1
|
|
|
673c78 |
|