Commit b6752625761f06493a89a02076323aa1a0d73819

Stefan Sperling 2018-12-24T17:28:46

fix an unchecked fwrite() call in got_object_blob_dump_to_file()

diff --git a/lib/object.c b/lib/object.c
index d504c3c..ddf52c6 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1111,7 +1111,7 @@ got_object_blob_dump_to_file(size_t *total_len, int *nlines,
     FILE *outfile, struct got_blob_object *blob)
 {
 	const struct got_error *err = NULL;
-	size_t len, hdrlen;
+	size_t n, len, hdrlen;
 	const uint8_t *buf;
 	int i;
 
@@ -1137,7 +1137,9 @@ got_object_blob_dump_to_file(size_t *total_len, int *nlines,
 			}
 		}
 		/* Skip blob object header first time around. */
-		fwrite(buf + hdrlen, len - hdrlen, 1, outfile);
+		n = fwrite(buf + hdrlen, len - hdrlen, 1, outfile);
+		if (n != len - hdrlen)
+			return got_ferror(outfile, GOT_ERR_IO);
 		hdrlen = 0;
 	} while (len != 0);