fix spurious errors in refactored passwd/group code
authorRich Felker <dalias@aerifal.cx>
Mon, 23 Feb 2015 05:42:40 +0000 (00:42 -0500)
committerRich Felker <dalias@aerifal.cx>
Mon, 23 Feb 2015 05:42:40 +0000 (00:42 -0500)
errno was treated as the error status when the return value of getline
was negative, but this condition can simply indicate EOF and is not
necessarily an error.

the spurious errors caused by this bug masked the bug which was fixed
in commit fc5a96c9c8aa186effad7520d5df6b616bbfd29d.

src/passwd/getgrent_a.c
src/passwd/getpwent_a.c

index bafc9ed..ecd2f2e 100644 (file)
@@ -18,7 +18,7 @@ int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***m
        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
        for (;;) {
                if ((l=getline(line, size, f)) < 0) {
-                       rv = errno;
+                       rv = ferror(f) ? errno : 0;
                        free(*line);
                        *line = 0;
                        gr = 0;
index 4d84f0d..d1b4b53 100644 (file)
@@ -17,7 +17,7 @@ int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct p
        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
        for (;;) {
                if ((l=getline(line, size, f)) < 0) {
-                       rv = errno;
+                       rv = ferror(f) ? errno : 0;
                        free(*line);
                        *line = 0;
                        pw = 0;