Skip to content

Commit

Permalink
logger: fix --size use for stdin
Browse files Browse the repository at this point in the history
The stdin version counts log header into the message size, but
for example when it reads message from argv[] it counts only message
itself.

 $ logger --stderr  --size 3 "abcd"
 <13>Oct 21 18:48:29 kzak: abc

 $ echo "abcd" | logger --stderr  --size 3
 logger: cannot allocate 18446744073709551597 bytes: Cannot allocate memory

Upstream: http://github.com/util-linux/util-linux/commit/58e4ee082bca100034791a4a74481f263bb30a25
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2033622
Signed-off-by: Karel Zak <[email protected]>
  • Loading branch information
karelzak committed Feb 7, 2022
1 parent 533d695 commit cac75d8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions misc-utils/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,7 @@ static void logger_stdin(struct logger_ctl *ctl)
int has_header = 1;
int default_priority = ctl->pri;
int last_pri = default_priority;
size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
char *const buf = xmalloc(max_usrmsg_size + 2 + 2);
char *buf = xmalloc(ctl->max_message_size + 2 + 2);
int pri;
int c;
size_t i;
Expand All @@ -1004,16 +1003,14 @@ static void logger_stdin(struct logger_ctl *ctl)
ctl->pri = default_priority;

if (ctl->pri != last_pri) {
has_header = 0;
max_usrmsg_size =
ctl->max_message_size - strlen(ctl->hdr);
generate_syslog_header(ctl);
last_pri = ctl->pri;
}
if (c != EOF && c != '\n')
c = getchar();
}

while (c != EOF && c != '\n' && i < max_usrmsg_size) {
while (c != EOF && c != '\n' && i < ctl->max_message_size) {
buf[i++] = c;
c = getchar();
}
Expand Down

0 comments on commit cac75d8

Please sign in to comment.