From 9ee95fa26acc939ef7ba1e5158dc61d33164e6aa Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 22 Jun 2021 16:50:46 +0200 Subject: [PATCH] utmpdump: do not use atoi() Addresses: https://github.com/karelzak/util-linux/issues/1358 Signed-off-by: Karel Zak --- login-utils/utmpdump.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c index b9a92b5f6..274f0d97a 100644 --- a/login-utils/utmpdump.c +++ b/login-utils/utmpdump.c @@ -74,8 +74,16 @@ static time_t strtotime(const char *s_time) static suseconds_t strtousec(const char *s_time) { const char *s = strchr(s_time, ','); - if (s) - return (suseconds_t) atoi(s + 1); + + if (s && *++s) { + suseconds_t us; + char *end = NULL; + + errno = 0; + us = strtol(s, &end, 10); + if (errno == 0 && end && end > s) + return us; + } return 0; } @@ -266,7 +274,7 @@ static int gettok(char *line, char *dest, int size, int eatspace) static void undump(FILE *in, FILE *out) { struct utmpx ut; - char s_addr[INET6_ADDRSTRLEN + 1], s_time[29], *linestart, *line; + char s_addr[INET6_ADDRSTRLEN + 1], s_time[29] = {}, *linestart, *line; linestart = xmalloc(1024 * sizeof(*linestart)); s_time[28] = 0;