Merge pull request #5337 from pks-t/pks/smart-pkt-ok-overflow smart_pkt: fix overflow resulting in OOB read/write of one byte
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);