Module Name:    src
Committed By:   riastradh
Date:           Sun Apr 16 20:49:09 UTC 2017

Modified Files:
        src/usr.bin/make: arch.c

Log Message:
Check return value of fseek.

CID 975275
CID 975276


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/make/arch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.69 src/usr.bin/make/arch.c:1.70
--- src/usr.bin/make/arch.c:1.69	Wed Apr  6 09:57:00 2016
+++ src/usr.bin/make/arch.c	Sun Apr 16 20:49:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.69 2016/04/06 09:57:00 gson Exp $	*/
+/*	$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.69 2016/04/06 09:57:00 gson Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.69 2016/04/06 09:57:00 gson Exp $");
+__RCSID("$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -679,7 +679,8 @@ ArchStatMember(char *archive, char *memb
 		if (fread(memName, elen, 1, arch) != 1)
 			goto badarch;
 		memName[elen] = '\0';
-		fseek(arch, -elen, SEEK_CUR);
+		if (fseek(arch, -elen, SEEK_CUR) != 0)
+			goto badarch;
 		if (DEBUG(ARCH) || DEBUG(MAKE)) {
 		    fprintf(debug_file, "ArchStat: Extended format entry for %s\n", memName);
 		}
@@ -690,7 +691,8 @@ ArchStatMember(char *archive, char *memb
 	    Hash_SetValue(he, bmake_malloc(sizeof(struct ar_hdr)));
 	    memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
 	}
-	fseek(arch, (size + 1) & ~1, SEEK_CUR);
+	if (fseek(arch, (size + 1) & ~1, SEEK_CUR) != 0)
+	    goto badarch;
     }
 
     fclose(arch);
@@ -909,7 +911,10 @@ ArchFindMember(char *archive, char *memb
 		 * the file at the actual member, rather than its header, but
 		 * not here...
 		 */
-		fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR);
+		if (fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR) != 0) {
+		    fclose(arch);
+		    return NULL;
+		}
 		return (arch);
 	    }
 	} else
@@ -939,10 +944,17 @@ ArchFindMember(char *archive, char *memb
 		}
 		if (strncmp(ename, member, len) == 0) {
 			/* Found as extended name */
-			fseek(arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR);
+			if (fseek(arch, -sizeof(struct ar_hdr) - elen,
+				SEEK_CUR) != 0) {
+			    fclose(arch);
+			    return NULL;
+			}
 			return (arch);
 		}
-		fseek(arch, -elen, SEEK_CUR);
+		if (fseek(arch, -elen, SEEK_CUR) != 0) {
+		    fclose(arch);
+		    return NULL;
+		}
 		goto skip;
 	} else
 #endif
@@ -957,7 +969,10 @@ skip:
 	     */
 	    arhPtr->ar_size[sizeof(arhPtr->ar_size)-1] = '\0';
 	    size = (int)strtol(arhPtr->ar_size, NULL, 10);
-	    fseek(arch, (size + 1) & ~1, SEEK_CUR);
+	    if (fseek(arch, (size + 1) & ~1, SEEK_CUR) != 0) {
+		fclose(arch);
+		return NULL;
+	    }
 	}
     }
 

Reply via email to