Skip to content

Fix 'invalid packet line' for ng packets containing errors#4763

Merged
pks-t merged 1 commit into
libgit2:masterfrom
cschlack:fix_ng_packets
Aug 24, 2018
Merged

Fix 'invalid packet line' for ng packets containing errors#4763
pks-t merged 1 commit into
libgit2:masterfrom
cschlack:fix_ng_packets

Conversation

@cschlack

Copy link
Copy Markdown
Contributor

fixes #4762

@pks-t pks-t left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your report and fix.

While your change already impoves the code, I think there still is another issue. I've added some comments -- please let me know if you want to fix them, as well, otherwise I'll amend this PR.

len -= 3;
if (!(ptr = memchr(line, ' ', len)))

if (!(ptr = memchr(line, ' ', eol - line)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While exactly equivalent I agree that this helps readability


if (!(ptr = memchr(line, ' ', eol - line)))
goto out_err;
len = ptr - line;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the problem. We overwrite len with the length of the reference and thus loose track of the overall line length. Thus the following computations on len are invalid when we try to see how much characters are left in the pkt-line.

len -= 1;
if (!(ptr = memchr(line, '\n', len)))

if (!(ptr = memchr(line, '\n', eol - line)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer your eol-pointer thing. It reliefs us from always updating the len field, and thus is less error-prone.

Comment thread src/transports/smart_pkt.c Outdated
@@ -309,8 +311,8 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
if (len < 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't make a lot of sense in this context then, either, does it?

line = ptr + 1;
if (line >= eol)
    goto out_err;

Would make a lot more sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @pks-t , that was missing! I added it to my previous commit.

@cschlack

Copy link
Copy Markdown
Contributor Author

@pks-t I believe I fixed your requested change. Is there anything else you'd like me to change?

@pks-t pks-t merged commit 296cb5e into libgit2:master Aug 24, 2018
@pks-t

pks-t commented Aug 24, 2018

Copy link
Copy Markdown
Member

No, looks good to me. Thanks for your fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.27.4: invalid packet line

2 participants