Commit 0872c0b07dcdec507db636c063c1b96bf9cee9e1

Stefan Sperling 2020-03-18T16:11:30

more reasonable minimum length check in check_pack_hash()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/libexec/got-fetch-pack/got-fetch-pack.c b/libexec/got-fetch-pack/got-fetch-pack.c
index f274d7e..0847def 100644
--- a/libexec/got-fetch-pack/got-fetch-pack.c
+++ b/libexec/got-fetch-pack/got-fetch-pack.c
@@ -45,6 +45,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
+#include "got_lib_pack.h"
 
 #ifndef nitems
 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
@@ -165,7 +166,7 @@ check_pack_hash(int fd, size_t sz, uint8_t *hcomp)
 	uint8_t buf[32*1024];
 	ssize_t n, r, nr;
 
-	if (sz < 28)
+	if (sz < sizeof(struct got_packfile_hdr) + SHA1_DIGEST_LENGTH)
 		return got_error(GOT_ERR_BAD_PACKFILE);
 
 	n = 0;