From 55cbb788f8ff25737f66dc8d40e654e9594341f6 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 b9a92b5f67..274f0d97aa 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; -- 2.47.3