diff options
author | Daniel Willmann <dwillmann@sysmocom.de> | 2023-06-16 09:53:15 +0200 |
---|---|---|
committer | daniel <dwillmann@sysmocom.de> | 2023-06-19 15:12:24 +0000 |
commit | 7052cc6b3b714b56dc7007509e243708fc6d0d7c (patch) | |
tree | d69d6764fb8f48de59f28faf744ce3a4ac364843 | |
parent | c0aa4bdf8f5c3888813babcbc894305a4cac8561 (diff) |
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
-rw-r--r-- | src/core/socket.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index 1b147943..02e16bcc 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1550,6 +1550,11 @@ int osmo_sock_get_name_buf(char *str, size_t str_len, int fd) 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); |