Rewind stream if we fdopen sudoers since it may not be at the beginning.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 16 Apr 2009 12:22:04 +0000 (12:22 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 16 Apr 2009 12:22:04 +0000 (12:22 +0000)
Set the keepopen flag on already-open files too so the lexer doesn't
close them out from under us.

visudo.c

index 06d3b622c266e97641be78bb4ac7bd92191403e7..e9098f76741c4374f942eadff89b099251809364 100644 (file)
--- a/visudo.c
+++ b/visudo.c
@@ -782,8 +782,6 @@ open_sudoers(path, keepopen)
            sudoerslist.last->next = entry;
            sudoerslist.last = entry;
        }
-       if (keepopen != NULL)
-           *keepopen = TRUE;
     } else {
        /* Already exists, open .tmp version if there is one. */
        if (entry->tpath != NULL) {
@@ -792,8 +790,11 @@ open_sudoers(path, keepopen)
        } else {
            if ((fp = fdopen(entry->fd, "r")) == NULL)
                error(1, "%s", entry->path);
+           rewind(fp);
        }
     }
+    if (keepopen != NULL)
+       *keepopen = TRUE;
     return(fp);
 }