commit: 7ba3ab567aee55dfae0779a3d76c535fea2023d1
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Nov 13 12:52:20 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Nov 13 12:52:20 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7ba3ab56
qlop: check return from localtime in fmt_date
bogus input can result in NULL, crashing strftime
Thanks Agostino Sarubbo
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
qlop.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/qlop.c b/qlop.c
index 601ad87..95cd64b 100644
--- a/qlop.c
+++ b/qlop.c
@@ -204,13 +204,14 @@ static char _date_buf[48];
static char *fmt_date(struct qlop_mode *flags, time_t ts, time_t te)
{
time_t t = flags->do_endtime ? te : ts;
+ struct tm lt;
- if (flags->do_machine)
+ if (flags->do_machine || localtime_r(&t, <) == NULL)
snprintf(_date_buf, sizeof(_date_buf),
"%zd", (size_t)t);
else
strftime(_date_buf, sizeof(_date_buf),
- "%Y-%m-%dT%H:%M:%S", localtime(&t));
+ "%Y-%m-%dT%H:%M:%S", <);
return _date_buf;
}