Commit 8ced4627 by Christian Schlack Committed by Patrick Steinhardt

Fix 'invalid packet line' for ng packets containing errors

(cherry picked from commit 50dd7fea)
parent ffc20564
...@@ -290,7 +290,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len) ...@@ -290,7 +290,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len)
static int ng_pkt(git_pkt **out, const char *line, size_t len) static int ng_pkt(git_pkt **out, const char *line, size_t len)
{ {
git_pkt_ng *pkt; git_pkt_ng *pkt;
const char *ptr; const char *ptr, *eol;
size_t alloclen; size_t alloclen;
pkt = git__malloc(sizeof(*pkt)); pkt = git__malloc(sizeof(*pkt));
...@@ -299,11 +299,13 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len) ...@@ -299,11 +299,13 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
pkt->ref = NULL; pkt->ref = NULL;
pkt->type = GIT_PKT_NG; pkt->type = GIT_PKT_NG;
eol = line + len;
if (len < 3) if (len < 3)
goto out_err; goto out_err;
line += 3; /* skip "ng " */ line += 3; /* skip "ng " */
len -= 3;
if (!(ptr = memchr(line, ' ', len))) if (!(ptr = memchr(line, ' ', eol - line)))
goto out_err; goto out_err;
len = ptr - line; len = ptr - line;
...@@ -314,11 +316,11 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len) ...@@ -314,11 +316,11 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
memcpy(pkt->ref, line, len); memcpy(pkt->ref, line, len);
pkt->ref[len] = '\0'; pkt->ref[len] = '\0';
if (len < 1)
goto out_err;
line = ptr + 1; line = ptr + 1;
len -= 1; if (line >= eol)
if (!(ptr = memchr(line, '\n', len))) goto out_err;
if (!(ptr = memchr(line, '\n', eol - line)))
goto out_err; goto out_err;
len = ptr - line; len = ptr - line;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment