From: Karel Zak Date: Tue, 22 Jun 2021 14:50:46 +0000 (+0200) Subject: utmpdump: do not use atoi() X-Git-Tag: v2.37.1~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9ee95fa26acc939ef7ba1e5158dc61d33164e6aa;p=thirdparty%2Futil-linux.git utmpdump: do not use atoi() Addresses: https://github.com/karelzak/util-linux/issues/1358 Signed-off-by: Karel Zak --- 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;