-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
There was a problem hiding this 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))) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
src/transports/smart_pkt.c
Outdated
len -= 1; | ||
if (!(ptr = memchr(line, '\n', len))) | ||
|
||
if (!(ptr = memchr(line, '\n', eol - line))) |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b1c714f
to
47c4805
Compare
47c4805
to
50dd7fe
Compare
@pks-t I believe I fixed your requested change. Is there anything else you'd like me to change? |
No, looks good to me. Thanks for your fix! |
fixes #4762