Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Wed, 13 Nov 2019 12:53:33
Message-Id: 1573649540.7ba3ab567aee55dfae0779a3d76c535fea2023d1.grobian@gentoo
1 commit: 7ba3ab567aee55dfae0779a3d76c535fea2023d1
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Wed Nov 13 12:52:20 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Wed Nov 13 12:52:20 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7ba3ab56
7
8 qlop: check return from localtime in fmt_date
9
10 bogus input can result in NULL, crashing strftime
11
12 Thanks Agostino Sarubbo
13
14 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
15
16 qlop.c | 5 +++--
17 1 file changed, 3 insertions(+), 2 deletions(-)
18
19 diff --git a/qlop.c b/qlop.c
20 index 601ad87..95cd64b 100644
21 --- a/qlop.c
22 +++ b/qlop.c
23 @@ -204,13 +204,14 @@ static char _date_buf[48];
24 static char *fmt_date(struct qlop_mode *flags, time_t ts, time_t te)
25 {
26 time_t t = flags->do_endtime ? te : ts;
27 + struct tm lt;
28
29 - if (flags->do_machine)
30 + if (flags->do_machine || localtime_r(&t, &lt) == NULL)
31 snprintf(_date_buf, sizeof(_date_buf),
32 "%zd", (size_t)t);
33 else
34 strftime(_date_buf, sizeof(_date_buf),
35 - "%Y-%m-%dT%H:%M:%S", localtime(&t));
36 + "%Y-%m-%dT%H:%M:%S", &lt);
37
38 return _date_buf;
39 }