From 06ad0f64241677bc4fbaddc7efac35767bd13564 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 8 Jul 2015 15:13:14 -0600 Subject: [PATCH] Strip newline from /proc/stat btime line to avoid a strtonum() failure. From Jakub Wilk. --- plugins/sudoers/boottime.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; -- 2.40.0