-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Json read check json size #1709
Conversation
src/iperf_api.c
Outdated
hsize = ntohl(nsize); | ||
rc = Nread(fd, (char*) &nsize, sizeof(nsize), Ptcp); | ||
hsize = ntohl(nsize); | ||
if (rc == sizeof(nsize) && hsize > 0 && hsize <= MAX_PARAMS_JSON_STRING) { |
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.
Hey David, thank you for the pull request. We like this change, but we would prefer it if the rc check was separate and before we use the value of nsize. If Nread fails, it would be better to just fall through.
if (rc == sizeof(nsize)){
hsize = ntohl(nsize);
if (hsize > 0 && hsize <= MAX_PARAMS_JSON_STRING) {
...
}
}
Also, I realize it's not there now, but adding a print statement else if it fails the size checks would be helpful. Let us know what you think!
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.
Changes done (hopefully as requested).
d0b1cf8
to
d2a6ba6
Compare
Perfect! Thanks again for the pull request! |
Version of iperf3 (or development branch, such as
master
or3.1-STABLE
) to which this pull request applies:latest
Issues fixed (if any): None
Brief description of code changes (suitable for use as a commit message):
When receiving Params JSON size, verify that received exactly the
sizeof(<size variable>)
bytes.In addition, added a check that the size received is reasonable - positive and is less than 8KB (which probably is much more that needed and may be reduced).