From: Todd C. Miller Date: Wed, 8 Jul 2015 21:13:14 +0000 (-0600) Subject: Strip newline from /proc/stat btime line to avoid a strtonum() failure. X-Git-Tag: SUDO_1_8_14^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06ad0f64241677bc4fbaddc7efac35767bd13564;p=sudo Strip newline from /proc/stat btime line to avoid a strtonum() failure. From Jakub Wilk. --- diff --git a/plugins/sudoers/boottime.c b/plugins/sudoers/boottime.c index ad393b26e..72a7330bf 100644 --- a/plugins/sudoers/boottime.c +++ b/plugins/sudoers/boottime.c @@ -60,6 +60,7 @@ get_boottime(struct timespec *ts) char *line = NULL; size_t linesize = 0; bool found = false; + long long llval; ssize_t len; FILE *fp; debug_decl(get_boottime, SUDOERS_DEBUG_UTIL) @@ -69,7 +70,9 @@ get_boottime(struct timespec *ts) if (fp != NULL) { while ((len = getline(&line, &linesize, fp)) != -1) { if (strncmp(line, "btime ", 6) == 0) { - long long llval = strtonum(line + 6, 1, LLONG_MAX, NULL); + if (line[len - 1] == '\n') + line[len - 1] = '\0'; + llval = strtonum(line + 6, 1, LLONG_MAX, NULL); if (llval > 0) { ts->tv_sec = (time_t)llval; ts->tv_nsec = 0;