Commit 04c53c18246515277f8f093309035e992273819d

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

make got-fetch-pack check for NAK from server before the packfile arrives

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/libexec/got-fetch-pack/got-fetch-pack.c b/libexec/got-fetch-pack/got-fetch-pack.c
index 312015a..506a18d 100644
--- a/libexec/got-fetch-pack/got-fetch-pack.c
+++ b/libexec/got-fetch-pack/got-fetch-pack.c
@@ -584,7 +584,14 @@ fetch_pack(int fd, int packfd, struct got_object_id *packid,
 	err = readpkt(&n, fd, buf, sizeof(buf));
 	if (err)
 		goto done;
-	buf[n] = 0;
+	/*
+	 * For now, we only support a full clone, in which case the server
+	 * will now send a "NAK" (meaning no common objects were found).
+	 */
+	if (n != 4 || strncmp(buf, "NAK\n", n) != 0) {
+		err = got_error(GOT_ERR_BAD_PACKET);
+		goto done;
+	}
 
 	if (chattygit)
 		fprintf(stderr, "fetching...\n");