CID1129996: Unchecked return value from library
The function returns a value that indicates an error condition. If this is not
checked, the error condition may not be handled correctly.
In sp_opensocket: Value returned from a library function is not checked for
errors before being used. This value may indicate an error condition. (CWE-252)
Signed-off-by: Stefan Reinauer <stefan.reinauer(a)coreboot.org>
Index: serprog.c
===================================================================
--- serprog.c (revision 1763)
+++ serprog.c (working copy)
@@ -114,7 +114,11 @@
}
/* We are latency limited, and sometimes do write-write-read *
* (write-n) - so enable TCP_NODELAY. */
- setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));
+ if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int))) {
+ close(sock);
+ msg_perr("Error: serprog cannot set socket options: %s\n", strerror(errno));
+ return -1;
+ }
return sock;
}
#endif