Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 24, 2018

Conversation

cschlack
Copy link
Contributor

fixes #4762

Copy link
Member

@pks-t pks-t left a comment

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
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

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

if (!(ptr = memchr(line, ' ', eol - line)))
goto out_err;
len = ptr - line;
Copy link
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
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.

@@ -309,8 +311,8 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
if (len < 1)
Copy link
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
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
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
Copy link
Member

pks-t commented Aug 24, 2018

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