From a86896a1c7b8bb881591c027175491a18885de1b Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 22 Nov 2009 16:12:38 +0000 Subject: [PATCH] Don't exit() from open_sudoers, just return NULL for all errors. --- sudo.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sudo.c b/sudo.c index a92a25a16..d03a5635f 100644 --- a/sudo.c +++ b/sudo.c @@ -1161,17 +1161,21 @@ open_sudoers(sudoers, doedit, keepopen) log_error(NO_EXIT, "%s is owned by gid %lu, should be %lu", sudoers, (unsigned long) statbuf.st_gid, (unsigned long) SUDOERS_GID); else if ((fp = fopen(sudoers, "r")) == NULL) - log_error(USE_ERRNO, "can't open %s", sudoers); + log_error(USE_ERRNO|NO_EXIT, "can't open %s", sudoers); else { /* * Make sure we can actually read sudoers so we can present the * user with a reasonable error message (unlike the lexer). */ - if (statbuf.st_size != 0) { - if (fgetc(fp) == EOF) - log_error(USE_ERRNO, "can't read %s", sudoers); - rewind(fp); + if (statbuf.st_size != 0 && fgetc(fp) == EOF) { + log_error(USE_ERRNO|NO_EXIT, "can't read %s", sudoers); + fclose(fp); + fp = NULL; } + } + + if (fp != NULL) { + rewind(fp); (void) fcntl(fileno(fp), F_SETFD, 1); } -- 2.40.0