summaryrefslogtreecommitdiff
path: root/usr.bin/cap_mkdb/getinfo.c
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-03-10 05:20:36 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-03-10 05:20:36 +0000
commit854e57934fe88a38ea1781dc412d03381ef401ba (patch)
tree6ca5f13422def4309504f95168b866b48d4bfe73 /usr.bin/cap_mkdb/getinfo.c
parent21c2d4f31e47c7748835d64bf804739343ef1d8d (diff)
Don't ferror() after fclose().
Don't dereference NULL pointer if file is truncated. Sync with cgetnext(3). ok otto and millert
Diffstat (limited to 'usr.bin/cap_mkdb/getinfo.c')
-rw-r--r--usr.bin/cap_mkdb/getinfo.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/usr.bin/cap_mkdb/getinfo.c b/usr.bin/cap_mkdb/getinfo.c
index 160b806eb67..059c92f94b4 100644
--- a/usr.bin/cap_mkdb/getinfo.c
+++ b/usr.bin/cap_mkdb/getinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getinfo.c,v 1.8 2006/02/20 09:23:26 jmc Exp $ */
+/* $OpenBSD: getinfo.c,v 1.9 2006/03/10 05:20:35 ray Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -30,7 +30,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: getinfo.c,v 1.8 2006/02/20 09:23:26 jmc Exp $";
+static char rcsid[] = "$OpenBSD: getinfo.c,v 1.9 2006/03/10 05:20:35 ray Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -535,11 +535,12 @@ igetnext(char **bp, char **db_array)
for(;;) {
line = fgetln(pfp, &len);
if (line == NULL && pfp) {
- (void)fclose(pfp);
if (ferror(pfp)) {
(void)igetclose();
return (-1);
} else {
+ (void)fclose(pfp);
+ pfp = NULL;
if (*++dbp == NULL) {
(void)igetclose();
return (0);
@@ -551,7 +552,7 @@ igetnext(char **bp, char **db_array)
continue;
}
} else
- line[len - 1] = '\0';
+ line[len - 1] = '\0';/* XXX - assumes newline */
if (len == 1) {
slash = 0;
continue;
@@ -589,12 +590,19 @@ igetnext(char **bp, char **db_array)
} else { /* name field extends beyond the line */
line = fgetln(pfp, &len);
if (line == NULL && pfp) {
- (void)fclose(pfp);
if (ferror(pfp)) {
(void)igetclose();
return (-1);
}
+ /* Move on to next file. */
+ (void)fclose(pfp);
+ pfp = NULL;
+ ++dbp;
+ /* NUL terminate nbuf. */
+ *np = '\0';
+ break;
} else
+ /* XXX - assumes newline */
line[len - 1] = '\0';
}
}