Skip to content

Commit

Permalink
smart_pkt: verify packet length exceeds PKT_LEN_SIZE
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
pks-t authored and Edward Thomson committed Jan 6, 2017
1 parent 75db289 commit 66e3774
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/transports/smart_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ int git_pkt_parse_line(
if (bufflen > 0 && bufflen < (size_t)len)
return GIT_EBUFS;

/*
* The length has to be exactly 0 in case of a flush
* packet or greater than PKT_LEN_SIZE, as the decoded
* length includes its own encoded length of four bytes.
*/
if (len != 0 && len < PKT_LEN_SIZE)
return GIT_ERROR;

line += PKT_LEN_SIZE;
/*
* TODO: How do we deal with empty lines? Try again? with the next
Expand Down

0 comments on commit 66e3774

Please sign in to comment.