Strip newline from /proc/stat btime line to avoid a strtonum() failure.

From Jakub Wilk.
This commit is contained in:
Todd C. Miller
2015-07-08 15:13:14 -06:00
parent 61182c87ea
commit 06ad0f6424

View File

@@ -60,6 +60,7 @@ get_boottime(struct timespec *ts)
char *line = NULL; char *line = NULL;
size_t linesize = 0; size_t linesize = 0;
bool found = false; bool found = false;
long long llval;
ssize_t len; ssize_t len;
FILE *fp; FILE *fp;
debug_decl(get_boottime, SUDOERS_DEBUG_UTIL) debug_decl(get_boottime, SUDOERS_DEBUG_UTIL)
@@ -69,7 +70,9 @@ get_boottime(struct timespec *ts)
if (fp != NULL) { if (fp != NULL) {
while ((len = getline(&line, &linesize, fp)) != -1) { while ((len = getline(&line, &linesize, fp)) != -1) {
if (strncmp(line, "btime ", 6) == 0) { 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) { if (llval > 0) {
ts->tv_sec = (time_t)llval; ts->tv_sec = (time_t)llval;
ts->tv_nsec = 0; ts->tv_nsec = 0;