Commit 12f2167a2e638b44a8d0c2c163448011485067b3

Stefan Sperling 2021-07-04T16:24:52

add checksum parameters to got_inflate functions which did not provide them yet

diff --git a/lib/got_lib_inflate.h b/lib/got_lib_inflate.h
index 0ccf42c..ad8c052 100644
--- a/lib/got_lib_inflate.h
+++ b/lib/got_lib_inflate.h
@@ -46,14 +46,16 @@ const struct got_error *got_inflate_read_mmap(struct got_inflate_buf *,
     uint8_t *, size_t, size_t, size_t *, size_t *);
 void got_inflate_end(struct got_inflate_buf *);
 const struct got_error *got_inflate_to_mem(uint8_t **, size_t *, size_t *,
-    FILE *);
+    struct got_inflate_checksum *, FILE *);
 const struct got_error *got_inflate_to_mem_fd(uint8_t **, size_t *, size_t *,
     struct got_inflate_checksum *, size_t, int);
 const struct got_error *got_inflate_to_mem_mmap(uint8_t **, size_t *, size_t *,
     struct got_inflate_checksum *, uint8_t *, size_t, size_t);
-const struct got_error *got_inflate_to_file(size_t *, FILE *, FILE *);
+const struct got_error *got_inflate_to_file(size_t *, FILE *,
+    struct got_inflate_checksum *, FILE *);
 const struct got_error *got_inflate_to_file_fd(size_t *, size_t *,
     struct got_inflate_checksum *, int, FILE *);
-const struct got_error *got_inflate_to_fd(size_t *, FILE *, int);
+const struct got_error *got_inflate_to_fd(size_t *, FILE *,
+    struct got_inflate_checksum *, int);
 const struct got_error *got_inflate_to_file_mmap(size_t *, size_t *,
     struct got_inflate_checksum *, uint8_t *, size_t, size_t, FILE *);
diff --git a/lib/inflate.c b/lib/inflate.c
index 1197bbb..aa993fb 100644
--- a/lib/inflate.c
+++ b/lib/inflate.c
@@ -262,7 +262,7 @@ got_inflate_end(struct got_inflate_buf *zb)
 
 const struct got_error *
 got_inflate_to_mem(uint8_t **outbuf, size_t *outlen,
-    size_t *consumed_total, FILE *f)
+    size_t *consumed_total, struct got_inflate_checksum *csum, FILE *f)
 {
 	const struct got_error *err;
 	size_t avail, consumed;
@@ -274,9 +274,9 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen,
 		*outbuf = malloc(GOT_INFLATE_BUFSIZE);
 		if (*outbuf == NULL)
 			return got_error_from_errno("malloc");
-		err = got_inflate_init(&zb, *outbuf, GOT_INFLATE_BUFSIZE, NULL);
+		err = got_inflate_init(&zb, *outbuf, GOT_INFLATE_BUFSIZE, csum);
 	} else
-		err = got_inflate_init(&zb, NULL, GOT_INFLATE_BUFSIZE, NULL);
+		err = got_inflate_init(&zb, NULL, GOT_INFLATE_BUFSIZE, csum);
 	if (err)
 		return err;
 
@@ -437,13 +437,14 @@ done:
 }
 
 const struct got_error *
-got_inflate_to_fd(size_t *outlen, FILE *infile, int outfd)
+got_inflate_to_fd(size_t *outlen, FILE *infile,
+    struct got_inflate_checksum *csum, int outfd)
 {
 	const struct got_error *err = NULL;
 	size_t avail;
 	struct got_inflate_buf zb;
 
-	err = got_inflate_init(&zb, NULL, GOT_INFLATE_BUFSIZE, NULL);
+	err = got_inflate_init(&zb, NULL, GOT_INFLATE_BUFSIZE, csum);
 	if (err)
 		goto done;
 
@@ -474,13 +475,14 @@ done:
 }
 
 const struct got_error *
-got_inflate_to_file(size_t *outlen, FILE *infile, FILE *outfile)
+got_inflate_to_file(size_t *outlen, FILE *infile,
+    struct got_inflate_checksum *csum, FILE *outfile)
 {
 	const struct got_error *err;
 	size_t avail;
 	struct got_inflate_buf zb;
 
-	err = got_inflate_init(&zb, NULL, GOT_INFLATE_BUFSIZE, NULL);
+	err = got_inflate_init(&zb, NULL, GOT_INFLATE_BUFSIZE, csum);
 	if (err)
 		goto done;
 
diff --git a/libexec/got-read-blob/got-read-blob.c b/libexec/got-read-blob/got-read-blob.c
index 092a8f9..59f45b5 100644
--- a/libexec/got-read-blob/got-read-blob.c
+++ b/libexec/got-read-blob/got-read-blob.c
@@ -146,11 +146,11 @@ main(int argc, char *argv[])
 
 		if (obj->size + obj->hdrlen <=
 		    GOT_PRIVSEP_INLINE_BLOB_DATA_MAX) {
-			err = got_inflate_to_mem(&buf, &size, NULL, f);
+			err = got_inflate_to_mem(&buf, &size, NULL, NULL, f);
 			if (err)
 				goto done;
 		} else {
-			err = got_inflate_to_fd(&size, f, imsg_outfd.fd);
+			err = got_inflate_to_fd(&size, f, NULL, imsg_outfd.fd);
 			if (err)
 				goto done;
 		}
diff --git a/libexec/got-read-commit/got-read-commit.c b/libexec/got-read-commit/got-read-commit.c
index 41be1ea..93245b3 100644
--- a/libexec/got-read-commit/got-read-commit.c
+++ b/libexec/got-read-commit/got-read-commit.c
@@ -55,7 +55,7 @@ read_commit_object(struct got_commit_object **commit, FILE *f)
 	size_t len;
 	uint8_t *p;
 
-	err = got_inflate_to_mem(&p, &len, NULL, f);
+	err = got_inflate_to_mem(&p, &len, NULL, NULL, f);
 	if (err)
 		return err;
 
diff --git a/libexec/got-read-object/got-read-object.c b/libexec/got-read-object/got-read-object.c
index 8cb2bc3..d91d50b 100644
--- a/libexec/got-read-object/got-read-object.c
+++ b/libexec/got-read-object/got-read-object.c
@@ -78,9 +78,9 @@ send_raw_obj(struct imsgbuf *ibuf, struct got_object *obj, int fd, int outfd)
 	}
 
 	if (obj->size + obj->hdrlen <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX)
-		err = got_inflate_to_mem(&data, &len, &consumed, f);
+		err = got_inflate_to_mem(&data, &len, &consumed, NULL, f);
 	else
-		err = got_inflate_to_fd(&len, f, outfd);
+		err = got_inflate_to_fd(&len, f, NULL, outfd);
 	if (err)
 		goto done;
 
diff --git a/libexec/got-read-tag/got-read-tag.c b/libexec/got-read-tag/got-read-tag.c
index 2ee8df0..f3ce48d 100644
--- a/libexec/got-read-tag/got-read-tag.c
+++ b/libexec/got-read-tag/got-read-tag.c
@@ -55,7 +55,7 @@ read_tag_object(struct got_tag_object **tag, FILE *f)
 	size_t len;
 	uint8_t *p;
 
-	err = got_inflate_to_mem(&p, &len, NULL, f);
+	err = got_inflate_to_mem(&p, &len, NULL, NULL, f);
 	if (err)
 		return err;
 
diff --git a/libexec/got-read-tree/got-read-tree.c b/libexec/got-read-tree/got-read-tree.c
index 03b252f..aab6f58 100644
--- a/libexec/got-read-tree/got-read-tree.c
+++ b/libexec/got-read-tree/got-read-tree.c
@@ -56,7 +56,7 @@ read_tree_object(struct got_pathlist_head *entries, int *nentries,
 	struct got_object *obj;
 	size_t len;
 
-	err = got_inflate_to_mem(p, &len, NULL, f);
+	err = got_inflate_to_mem(p, &len, NULL, NULL, f);
 	if (err)
 		return err;