Skip to content

Commit

Permalink
transport: safely handle messages with no caps
Browse files Browse the repository at this point in the history
If there are no caps, don't try to advance past the first NULL to look
for object-format. This prevents a possible out-of-bounds read.
  • Loading branch information
ethomson committed Jan 12, 2024
1 parent a2bde63 commit d298b02
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libgit2/transports/smart_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ static int set_data(

GIT_ASSERT_ARG(data);

if ((caps = memchr(line, '\0', len)) != NULL) {
if ((caps = memchr(line, '\0', len)) != NULL &&
len > (size_t)((caps - line) + 1)) {
caps++;

if (strncmp(caps, "object-format=", CONST_STRLEN("object-format=")) == 0)
Expand Down

0 comments on commit d298b02

Please sign in to comment.