]> granicus.if.org Git - sudo/commitdiff
If we can open sudoers but fail to read the first byte, close the
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 14 Aug 2007 14:04:41 +0000 (14:04 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 14 Aug 2007 14:04:41 +0000 (14:04 +0000)
file stream before trying again.

sudo.c

diff --git a/sudo.c b/sudo.c
index 5ebd6e47cce59cf5dd719ea03f7c94a8b48991c6..2f17db4a29d326e61ee13e05ed5e3ee32fac3dca 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -978,7 +978,6 @@ open_sudoers(sudoers, keepopen)
 {
     struct stat statbuf;
     FILE *fp = NULL;
-    char c;
     int rootstat, i;
 
     /*
@@ -1030,8 +1029,9 @@ open_sudoers(sudoers, keepopen)
        /* Solaris sometimes returns EAGAIN so try 10 times */
        for (i = 0; i < 10 ; i++) {
            errno = 0;
-           if ((fp = fopen(sudoers, "r")) == NULL ||
-               fread(&c, sizeof(c), 1, fp) != 1) {
+           if ((fp = fopen(sudoers, "r")) == NULL || fgetc(fp) == EOF) {
+               if (fp != NULL)
+                   fclose(fp);
                fp = NULL;
                if (errno != EAGAIN && errno != EWOULDBLOCK)
                    break;