ensure unix socket paths are NUL-terminated for bind/connect
The unix(7) man page recommends that sun_path is NUL-terminated when struct sockaddr_un is passed to a bind() or connect() call. Non-NUL-terminated paths only need to be dealt with at the receiving end of a UNIX domain socket. Commitb24efa5
erroneously assumed otherwise. Change-Id: I9beecfa500db75cb679b1edcc352c893bf098b13 Fixes:b24efa551d
Related: OS#2673
This commit is contained in:
parent
47e9e63bd5
commit
0d7d0b0a86
|
@ -101,10 +101,10 @@ DEFUN(cfg_e1line_socket, cfg_e1_line_socket_cmd,
|
|||
int e1_nr = atoi(argv[0]);
|
||||
struct sockaddr_un sun;
|
||||
|
||||
/* Don't exceed the maximum unix socket path length. See the unix(7) man page.*/
|
||||
if (strlen(argv[1]) > sizeof(sun.sun_path)) {
|
||||
/* Don't exceed the maximum unix socket path length, including a NUL byte. See the unix(7) man page.*/
|
||||
if (strlen(argv[1]) > sizeof(sun.sun_path) - 1) {
|
||||
vty_out(vty, "%% Socket path length exceeds %zd bytes: '%s'%s",
|
||||
sizeof(sun.sun_path), argv[1], VTY_NEWLINE);
|
||||
sizeof(sun.sun_path) - 1, argv[1], VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ static void unixsocket_write_msg_lapd_cb(struct msgb *msg, void *cbdata)
|
|||
static int unixsocket_line_update(struct e1inp_line *line)
|
||||
{
|
||||
struct unixsocket_line *config;
|
||||
char default_sock_path[sizeof(struct sockaddr_un) + 1]; /* see unix(7) man page */
|
||||
struct sockaddr_un un;
|
||||
const char *sock_path;
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
@ -252,9 +252,17 @@ static int unixsocket_line_update(struct e1inp_line *line)
|
|||
|
||||
/* Open unix domain socket */
|
||||
if (line->sock_path == NULL) {
|
||||
snprintf(default_sock_path, sizeof(default_sock_path), "%s%d",
|
||||
UNIXSOCKET_SOCK_PATH_DEFAULT, line->num);
|
||||
sock_path = default_sock_path;
|
||||
ret = snprintf(un.sun_path, sizeof(un.sun_path), "%s%d",
|
||||
UNIXSOCKET_SOCK_PATH_DEFAULT, line->num);
|
||||
if (ret == -1) {
|
||||
LOGP(DLINP, LOGL_ERROR, "Cannot create default socket path: %s\n", strerror(errno));
|
||||
return -errno;
|
||||
} else if (ret >= sizeof(un.sun_path)) {
|
||||
LOGP(DLINP, LOGL_ERROR, "Default socket path exceeds %zd bytes: %s%d\n",
|
||||
sizeof(un.sun_path), UNIXSOCKET_SOCK_PATH_DEFAULT, line->num);
|
||||
return -ENOSPC;
|
||||
}
|
||||
sock_path = un.sun_path;
|
||||
} else
|
||||
sock_path = line->sock_path;
|
||||
ret = osmo_sock_unix_init(SOCK_SEQPACKET, 0, sock_path,
|
||||
|
|
Loading…
Reference in New Issue