Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

parser->nread is incorrect at on_headers_complete #451

Open
jcwcmimik opened this issue Dec 1, 2018 · 1 comment
Open

parser->nread is incorrect at on_headers_complete #451

jcwcmimik opened this issue Dec 1, 2018 · 1 comment

Comments

@jcwcmimik
Copy link

master branch as of commit 4dae120, http_parser.c:1788

Neither SET_ERRNO nor RETURN are necessarily called in this case (s_headers_almost_done) and thus when on_headers_complete(parser) is called, parser still contains an old nread value (0 if it's the first parse attempt).

In my test cases, inserting parser->nread = nread; just before line 1788 solves the issue, but based on that assignment being contained solely within the SET_ERRNO and RETURN defines, someone more familiary with the code may wish to implement it elsewhere.

@bnoordhuis
Copy link
Member

bnoordhuis commented Dec 2, 2018

p->nread is only for tracking if we moved past HTTP_MAX_HEADER_SIZE. At line 1788, that doesn't matter anymore because we're done parsing headers.

I've fixed off-by-one errors in the past but that's not that useful here, it'd only benefit downstream users that inappropriately use p->nread. It's private and marked as such in http_parser.h but some projects still use it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants