dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
e86b25
From 7cc5bcfcb2340266a6b42370c9c4c02d8a325d5f Mon Sep 17 00:00:00 2001
e86b25
From: Karel Zak <kzak@redhat.com>
e86b25
Date: Thu, 21 Oct 2021 18:47:40 +0200
e86b25
Subject: [PATCH 67/74] logger: fix --size use for stdin
e86b25
MIME-Version: 1.0
e86b25
Content-Type: text/plain; charset=UTF-8
e86b25
Content-Transfer-Encoding: 8bit
e86b25
e86b25
The stdin version counts log header into the message size, but
e86b25
for example when it reads message from argv[] it counts only message
e86b25
itself.
e86b25
e86b25
 $ logger --stderr  --size 3 "abcd"
e86b25
 <13>Oct 21 18:48:29 kzak: abc
e86b25
e86b25
 $ echo "abcd" | logger --stderr  --size 3
e86b25
 logger: cannot allocate 18446744073709551597 bytes: Cannot allocate memory
e86b25
e86b25
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2011602
e86b25
Upstream: http://github.com/util-linux/util-linux/commit/58e4ee082bca100034791a4a74481f263bb30a25
e86b25
Signed-off-by: Karel Zak <kzak@redhat.com>
e86b25
---
e86b25
 misc-utils/logger.c | 16 ++++------------
e86b25
 1 file changed, 4 insertions(+), 12 deletions(-)
e86b25
e86b25
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
e86b25
index ebdc56ec2..c20ef05f1 100644
e86b25
--- a/misc-utils/logger.c
e86b25
+++ b/misc-utils/logger.c
e86b25
@@ -957,11 +957,9 @@ static void logger_stdin(struct logger_ctl *ctl)
e86b25
 	 * update header timestamps and to reflect possible priority changes.
e86b25
 	 * The initial header is generated by logger_open().
e86b25
 	 */
e86b25
-	int has_header = 1;
e86b25
 	int default_priority = ctl->pri;
e86b25
 	int last_pri = default_priority;
e86b25
-	size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
e86b25
-	char *const buf = xmalloc(max_usrmsg_size + 2 + 2);
e86b25
+	char *buf = xmalloc(ctl->max_message_size + 2 + 2);
e86b25
 	int pri;
e86b25
 	int c;
e86b25
 	size_t i;
e86b25
@@ -988,27 +986,21 @@ static void logger_stdin(struct logger_ctl *ctl)
e86b25
 				ctl->pri = default_priority;
e86b25
 
e86b25
 			if (ctl->pri != last_pri) {
e86b25
-				has_header = 0;
e86b25
-				max_usrmsg_size =
e86b25
-				    ctl->max_message_size - strlen(ctl->hdr);
e86b25
+				generate_syslog_header(ctl);
e86b25
 				last_pri = ctl->pri;
e86b25
 			}
e86b25
 			if (c != EOF && c != '\n')
e86b25
 				c = getchar();
e86b25
 		}
e86b25
 
e86b25
-		while (c != EOF && c != '\n' && i < max_usrmsg_size) {
e86b25
+		while (c != EOF && c != '\n' && i < ctl->max_message_size) {
e86b25
 			buf[i++] = c;
e86b25
 			c = getchar();
e86b25
 		}
e86b25
 		buf[i] = '\0';
e86b25
 
e86b25
-		if (i > 0 || !ctl->skip_empty_lines) {
e86b25
-			if (!has_header)
e86b25
-				generate_syslog_header(ctl);
e86b25
+		if (i > 0 || !ctl->skip_empty_lines)
e86b25
 			write_output(ctl, buf);
e86b25
-			has_header = 0;
e86b25
-		}
e86b25
 
e86b25
 		if (c == '\n')	/* discard line terminator */
e86b25
 			c = getchar();
e86b25
-- 
e86b25
2.31.1
e86b25