Fix 'invalid packet line' for ng packets containing errors#4763
Conversation
pks-t
left a comment
There was a problem hiding this comment.
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.
While exactly equivalent I agree that this helps readability
|
|
||
| if (!(ptr = memchr(line, ' ', eol - line))) | ||
| goto out_err; | ||
| len = ptr - line; |
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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) | |||
There was a problem hiding this comment.
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.
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