Commit ecf6e46eb15fefb32da8d87c34db1c6983368cc2

Stefan Sperling 2018-04-01T17:21:25

check for fopen() failures in got_diffreg()

diff --git a/lib/diffreg.c b/lib/diffreg.c
index c20c1b3..813bce5 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -299,16 +299,21 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 		*rval = (S_ISDIR(ds->stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
 		return NULL;
 	}
-	if (flags & D_EMPTY1)
+	if (flags & D_EMPTY1) {
 		f1 = fopen(_PATH_DEVNULL, "r");
+		if (f1 == NULL)
+			return got_error_from_errno();
+	}
 	else if (f1 == NULL) {
 		args->status |= 2;
 		goto closem;
 	}
 
-	if (flags & D_EMPTY2)
+	if (flags & D_EMPTY2) {
 		f2 = fopen(_PATH_DEVNULL, "r");
-	else if (f2 == NULL) {
+		if (f2 == NULL)
+			return got_error_from_errno();
+	} else if (f2 == NULL) {
 		args->status |= 2;
 		goto closem;
 	}