]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
utmpdump: do not use atoi()
authorKarel Zak <kzak@redhat.com>
Tue, 22 Jun 2021 14:50:46 +0000 (16:50 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Jul 2021 09:49:57 +0000 (11:49 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/utmpdump.c

index b9a92b5f6766154ea8b938706176ecc87f7786c0..274f0d97aa0d9fd03e6f61ea952fb2e1d3622d7a 100644 (file)
@@ -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;