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

Add error handling for close socket #1619

Merged
merged 1 commit into from
May 24, 2024
Merged

Conversation

maks-mishin
Copy link
Contributor

@maks-mishin maks-mishin commented Dec 12, 2023

  • Development branch: master

  • Issues fixed: add error handling for correct closing of socket s because of return with close socket leads to descriptor leak(CWE-403).

  • Brief description of code changes: added goto label with correct exit from function if necessary.

@ProjectMutilation
Copy link

ProjectMutilation commented Dec 13, 2023

@maks-mishin this isn't correct, mark of error_handling must be after return 0, now the function always return -1
probably you should added variable int ret and initialize it 0, and in error cases

    ret = -1;
    goto error_handling;
    ...
    error_handling:
        close(s);
        return ret;

p.s. not memleak, file descriptor leak(CWE-403)

src/iperf_server_api.c Show resolved Hide resolved
src/iperf_server_api.c Show resolved Hide resolved
src/iperf_server_api.c Outdated Show resolved Hide resolved
@maks-mishin
Copy link
Contributor Author

@ProjectMutilation, thanks for comments and advice.
I will fix it in the next commit.

Copy link
Contributor

@bmah888 bmah888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and comments! Plugging this file descriptor leak is definitely a good thing. I'm thinking about the use of the variable ret, it's only defined in one place (and only ever initialized to -1), and we only reference the value of ret in the two error exit cases. I'm not sure that's much better than just returning with the numeric literal -1.

I'm going to approve this for merging as-is, and going to sit on it a little bit to see if we want to iterate this a bit or not. The code change is definitely an improvement.

@bmah888 bmah888 self-assigned this May 24, 2024
@bmah888 bmah888 merged commit 8f5a87e into esnet:master May 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants