Skip to content

Commit 9ada072

Browse files
authored
Merge pull request libgit2#4758 from pks-t/pks/smart-pkt-oob-read
smart_pkt: fix potential OOB-read when processing ng packet
2 parents c9ad250 + 19bed3e commit 9ada072

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/transports/smart_pkt.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
291291
pkt->ref = NULL;
292292
pkt->type = GIT_PKT_NG;
293293

294+
if (len < 3)
295+
goto out_err;
294296
line += 3; /* skip "ng " */
295-
if (!(ptr = strchr(line, ' ')))
297+
len -= 3;
298+
if (!(ptr = memchr(line, ' ', len)))
296299
goto out_err;
297300
len = ptr - line;
298301

@@ -303,8 +306,11 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
303306
memcpy(pkt->ref, line, len);
304307
pkt->ref[len] = '\0';
305308

309+
if (len < 1)
310+
goto out_err;
306311
line = ptr + 1;
307-
if (!(ptr = strchr(line, '\n')))
312+
len -= 1;
313+
if (!(ptr = memchr(line, '\n', len)))
308314
goto out_err;
309315
len = ptr - line;
310316

0 commit comments

Comments
 (0)