daniel has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/33333 )

Change subject: socket: Ensure fd is not negative in osmo_sock_get_name_buf()
......................................................................

socket: Ensure fd is not negative in osmo_sock_get_name_buf()

Write to str even in case of error because this is already the current
behaviour and it's what osmo_stream_cli_get_sockname() and
osmo_sock_get_name2{,_c}() expect.

Change-Id: I76727993224ef87b475c33360c24966e82e866ec
Fixes: Coverity CID#321044
---
M src/core/socket.c
1 file changed, 19 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified




diff --git a/src/core/socket.c b/src/core/socket.c
index 1b14794..02e16bc 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1550,6 +1550,11 @@
        char portbuf_l[6], portbuf_r[6];
        int rc;

+       if (fd < 0) {
+               osmo_strlcpy(str, "<error-bad-fd>", str_len);
+               return -EBADF;
+       }
+
        /* get local */
        if ((rc = osmo_sock_get_ip_and_port(fd, hostbuf_l, sizeof(hostbuf_l), 
portbuf_l, sizeof(portbuf_l), true))) {
                osmo_strlcpy(str, "<error-in-getsockname>", str_len);

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33333
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I76727993224ef87b475c33360c24966e82e866ec
Gerrit-Change-Number: 33333
Gerrit-PatchSet: 2
Gerrit-Owner: daniel <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to