Commit e1d7747f23a3b2c09976c00685a754563ad6225e

Edward Thomson 2019-12-14T06:58:52

Merge pull request #5337 from pks-t/pks/smart-pkt-ok-overflow smart_pkt: fix overflow resulting in OOB read/write of one byte

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 9bc273e..56b680d 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -273,7 +273,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len)
 	line += 3;
 	len -= 3;
 
-	if (line[len - 1] == '\n')
+	if (len && line[len - 1] == '\n')
 		--len;
 
 	GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);