summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/socket.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/socket.c b/src/socket.c
index 6f56efb5..a85edb73 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -605,29 +605,27 @@ int osmo_sock_unix_init(uint16_t type, uint8_t proto,
struct sockaddr_un local;
int sfd, rc, on = 1;
unsigned int namelen;
- const size_t socket_path_len = strlen(socket_path);
if ((flags & (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) ==
(OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT))
return -EINVAL;
local.sun_family = AF_UNIX;
- if (socket_path_len == sizeof(local.sun_path)) {
- /* Handle corner-case where sun_path is not NUL-terminated. See the unix(7) man page. */
- memcpy(local.sun_path, socket_path, sizeof(local.sun_path));
- } else if (osmo_strlcpy(local.sun_path, socket_path, sizeof(local.sun_path)) >= sizeof(local.sun_path)) {
+ /* When an AF_UNIX socket is bound, sun_path should be NUL-terminated. See unix(7) man page. */
+ if (osmo_strlcpy(local.sun_path, socket_path, sizeof(local.sun_path)) >= sizeof(local.sun_path)) {
LOGP(DLGLOBAL, LOGL_ERROR, "Socket path exceeds maximum length of %zd bytes: %s\n",
sizeof(local.sun_path), socket_path);
return -ENOSPC;
}
#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
- local.sun_len = socket_path_len;
+ local.sun_len = strlen(local.sun_path);
#endif
#if defined(BSD44SOCKETS) || defined(SUN_LEN)
namelen = SUN_LEN(&local);
#else
- namelen = socket_path_len + offsetof(struct sockaddr_un, sun_path);
+ namelen = strlen(local.sun_path) +
+ offsetof(struct sockaddr_un, sun_path);
#endif
sfd = socket(AF_UNIX, type, proto);