Commit 5b7126c502f8d046d0779dd2cb0558163c383819

Omar Polo 2022-06-14T08:31:16

actually guarding against negative line offsets previous commit looked at some pretty zeroes returned from calloc instead of the actual numbers received.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/lib/patch.c b/lib/patch.c
index e14bc4b..7e310ae 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -242,12 +242,12 @@ recv_patch(struct imsgbuf *ibuf, int *done, struct got_patch *p, int strip)
 				goto done;
 			}
 			memcpy(&hdr, imsg.data, sizeof(hdr));
-			if ((h = calloc(1, sizeof(*h))) == NULL) {
-				err = got_error_from_errno("calloc");
+			if (hdr.oldfrom < 0 || hdr.newfrom < 0) {
+				err = got_error(GOT_ERR_PRIVSEP_LEN);
 				goto done;
 			}
-			if (h->old_from < 0 || h->new_from < 0) {
-				err = got_error(GOT_ERR_PRIVSEP_LEN);
+			if ((h = calloc(1, sizeof(*h))) == NULL) {
+				err = got_error_from_errno("calloc");
 				goto done;
 			}
 			h->old_from = hdr.oldfrom;