From fd4ab7fc074bd498cf3708cfbee60277808c20be Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Mon, 6 Aug 2018 11:32:04 -0400 Subject: [PATCH] journal.cc: Add more overflow checks (#570) --- src/journal.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/journal.cc b/src/journal.cc index c52bf784..7098b922 100644 --- a/src/journal.cc +++ b/src/journal.cc @@ -88,6 +88,8 @@ void init_journal(const char *type, const char *arg, struct text_object *obj, CRIT_ERR(obj, free_at_crash, "invalid arg for %s, type must be 'system' or 'user'", type); } + } else { + NORM_ERR("You should type a 'user' or 'system' as an argument"); } } else { @@ -114,7 +116,13 @@ static int print_field(sd_journal *jh, const char *field, char spacer, *read += length - fieldlen; out: - if (spacer) p[(*read)++] = spacer; + if (spacer) { + if (p_max_size < *read) { + *read = p_max_size - 1; + } else { + p[(*read)++] = spacer; + } + } return length ? length - fieldlen : 0; }