Skip to content

Commit 66e3774

Browse files
pks-tEdward Thomson
authored andcommitted
smart_pkt: verify packet length exceeds PKT_LEN_SIZE
Each packet line in the Git protocol is prefixed by a four-byte length of how much data will follow, which we parse in `git_pkt_parse_line`. The transmitted length can either be equal to zero in case of a flush packet or has to be at least of length four, as it also includes the encoded length itself. Not checking this may result in a buffer overflow as we directly pass the length to functions which accept a `size_t` length as parameter. Fix the issue by verifying that non-flush packets have at least a length of `PKT_LEN_SIZE`.
1 parent 75db289 commit 66e3774

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/transports/smart_pkt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ int git_pkt_parse_line(
427427
if (bufflen > 0 && bufflen < (size_t)len)
428428
return GIT_EBUFS;
429429

430+
/*
431+
* The length has to be exactly 0 in case of a flush
432+
* packet or greater than PKT_LEN_SIZE, as the decoded
433+
* length includes its own encoded length of four bytes.
434+
*/
435+
if (len != 0 && len < PKT_LEN_SIZE)
436+
return GIT_ERROR;
437+
430438
line += PKT_LEN_SIZE;
431439
/*
432440
* TODO: How do we deal with empty lines? Try again? with the next

0 commit comments

Comments
 (0)