aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2024-02-27 16:10:22 +0100
committerKarel Zak <kzak@redhat.com>2024-02-27 16:10:22 +0100
commit16926147cb346fc3245b4ea5e4cb0fc47a4f198f (patch)
treeed07f6491e397c8e6c7c65a0d257485c3a1a979b
parent805911b7d5449379135d156661e4fdc2c79b4641 (diff)
parent0e5031a425c727b16831c108a92271e240c29595 (diff)
downloadutil-linux-16926147cb346fc3245b4ea5e4cb0fc47a4f198f.tar.gz
Merge branch 'PR/dmesg-2807' of github.com:karelzak/util-linux-work
* 'PR/dmesg-2807' of github.com:karelzak/util-linux-work: dmesg: fix wrong size calculation
-rw-r--r--sys-utils/dmesg.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 48282f1e6c..25c674be3b 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -939,13 +939,17 @@ static int get_next_syslog_record(struct dmesg_control *ctl,
const char *start = begin + 1;
size_t id_size;
- start = start + strspn(start, " ");
+ while (start < end && *start == ' ')
+ start++;
+
begin = skip_item(begin, end, "]");
id_size = begin - start;
+
if (id_size < sizeof(rec->caller_id))
xstrncpy(rec->caller_id, start, id_size);
- rec->mesg = begin + 1;
- rec->mesg_size = end - begin - 1;
+
+ rec->mesg = begin < end ? begin + 1 : NULL;
+ rec->mesg_size = begin < end ? end - begin - 1 : 0;
} else {
rec->mesg = begin;
rec->mesg_size = end - begin;