-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Coverity CID :215391] Unchecked return value from library in samples/net/mdns_responder/src/service.c #33093
Comments
@pfalcon @jukkar @tbursztyka I see you are assigned to this, what do you think of my proposed solution below? 😃 I don't think a simple From here I can see information about the return value: https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html
So my solution would be something like this: static void welcome(int fd)
{
static const char msg[] = "Bonjour, Zephyr world!\n";
int r = send(fd, msg, sizeof(msg), 0);
if (r == -1) {
NET_DBG("send() failed (%d)", errno);
close(fd);
}
} I would also change the return type of void service(void)
{
// ... some code above ...
/* send a banner */
if(welcome(client_fd) == -1) {
return;
}
// ... some code below ...
} static int welcome(int fd)
{
static const char msg[] = "Bonjour, Zephyr world!\n";
int r = send(fd, msg, sizeof(msg), 0);
if (r == -1) {
NET_DBG("send() failed (%d)", errno);
close(fd);
return r;
}
return 0;
} |
Hi @GunZi200, your proposal looks fine. Can you send a PR for it? After looking the application, it tends to quit far too easy. So it works only once, and quits for any errors. It would need some more work to be more usable. Anyway, that is for another PR. |
@GunZi200 If you are at it, could you also fix #33094 which leaks server_fd, by not closing it if there is an error in bind() or listen() in service.c. Thanks in advance! |
Sure I’ll create a PR for both issues this evening :) |
Check return value if sendto() fails. Coverity-CID: 215391 Fixes #33093 Signed-off-by: Guðni Már Gilbert <[email protected]>
Static code scan issues found in file:
https:/zephyrproject-rtos/zephyr/tree/bd97359a5338b2542d19011b6d6aa1d8d1b9cc3f/samples/net/mdns_responder/src/service.c
Category: Error handling issues
Function:
welcome
Component: Samples
CID: 215391
Details:
zephyr/samples/net/mdns_responder/src/service.c
Line 26 in bd97359
Please fix or provide comments in coverity using the link:
https://scan9.coverity.com/reports.htm#v32951/p12996.
Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the CODEOWNERS file.
The text was updated successfully, but these errors were encountered: