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

Json read check json size #1709

Merged
merged 4 commits into from
Sep 20, 2024
Merged

Conversation

davidBar-On
Copy link
Contributor

@davidBar-On davidBar-On commented Jun 2, 2024

  • Version of iperf3 (or development branch, such as master or
    3.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).

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) {
Copy link
Contributor

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!

Copy link
Contributor Author

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

@swlars
Copy link
Contributor

swlars commented Sep 20, 2024

Perfect! Thanks again for the pull request!

@davidBar-On
Copy link
Contributor Author

@swlars, unfortunately this PR has a bug which was discovered by issue #1776. Submitted PR #1779 with a 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.

2 participants