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
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);