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

Check Return Value for setsockopt #1172

Open
ArielSAdamsNASA opened this issue Sep 29, 2021 · 3 comments
Open

Check Return Value for setsockopt #1172

ArielSAdamsNASA opened this issue Sep 29, 2021 · 3 comments
Assignees
Labels
bug good first issue Good for newcomers

Comments

@ArielSAdamsNASA
Copy link
Contributor

Describe the bug
Calling setsockopt(impl->fd, 1, 2, &os_flags, 4U) without checking return value. This library function may fail and return an error code.

Expected behavior
Check return value for setsockopt

Code snips

setsockopt(impl->fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags));

System observed on:
Coverity: https://scan.coverity.com/projects/arielsadamsnasa-cfs-jsf-rules?tab=overview

Additional context
Possible solution

if (setsockopt(impl->fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags)) == 0)
{
    setsockopt(impl->fd, SOL_SOCKET, SO_REUSEADDR, &os_flags, sizeof(os_flags));
}

Reporter Info
Ariel Adams, ASRC Federal

@himanshu007-creator
Copy link

hi i would like to work on this issue

@ArielSAdamsNASA
Copy link
Contributor Author

@himanshu007-creator Thank you for the participation! I assigned you to this issue.

jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Fix nasa#1172, Update to use Ut_Stub_CheckDefaultReturnValue API
@skliper
Copy link
Contributor

skliper commented Oct 14, 2022

@ArielSAdamsNASA @himanshu007-creator - I'm not sure this solution solves an actual issue. This suggestion just does the same call again if the first fails which doesn't seem to be any better (odds are it'll just fail again). Although it is a static analysis warning, it's already documented (in comments) that if the call fails there isn't a need to take any further action. I'd recommend just closing this issue and the related pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants