This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/10647 )
Change subject: Properly deal with sockaddr_un socket path length limitations.
......................................................................
Properly deal with sockaddr_un socket path length limitations.
When parsing the configuration, reject a socket path which
exceeds the maximum size supported by the operating system.
In unixsocket_line_update() stop copying the line's socket path to a
local buffer. The path will be copied again in osmo_sock_unix_init().
Both changes are portable; we don't assume any particular socket
path length since the size differs between implementations of Unix,
and we rely only on information from the generic sys/un.h header.
Change-Id: I36344805a825f5d0e0c9d218d438d8fd985ed9ca
Related: OS#2673
---
M src/e1_input_vty.c
M src/input/unixsocket.c
2 files changed, 18 insertions(+), 7 deletions(-)
Approvals:
Jenkins Builder: Verified
Pau Espin Pedrol: Looks good to me, approved
diff --git a/src/e1_input_vty.c b/src/e1_input_vty.c
index 0e4575f..653c573 100644
--- a/src/e1_input_vty.c
+++ b/src/e1_input_vty.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <sys/un.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/talloc.h>
@@ -98,6 +99,14 @@
{
struct e1inp_line *line;
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)) {
+ vty_out(vty, "%% Socket path length exceeds %zd bytes: '%s'%s",
+ sizeof(sun.sun_path), argv[1], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
line = e1inp_line_find(e1_nr);
if (!line) {
diff --git a/src/input/unixsocket.c b/src/input/unixsocket.c
index c49928d..00e1f9b 100644
--- a/src/input/unixsocket.c
+++ b/src/input/unixsocket.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
+#include <sys/un.h>
#include <limits.h>
#include <string.h>
@@ -228,16 +229,11 @@
static int unixsocket_line_update(struct e1inp_line *line)
{
struct unixsocket_line *config;
- char sock_path[PATH_MAX];
+ char default_sock_path[sizeof(struct sockaddr_un) + 1]; /* see unix(7) man page */
+ const char *sock_path;
int ret = 0;
int i;
- if (line->sock_path)
- osmo_strlcpy(sock_path, line->sock_path, PATH_MAX);
- else
- sprintf(sock_path, "%s%d", UNIXSOCKET_SOCK_PATH_DEFAULT,
- line->num);
-
LOGP(DLINP, LOGL_NOTICE, "line update (line=%p)\n", line);
if (!line->driver_data)
@@ -255,6 +251,12 @@
config->fd.cb = unixsocket_cb;
/* 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;
+ } else
+ sock_path = line->sock_path;
ret = osmo_sock_unix_init(SOCK_SEQPACKET, 0, sock_path,
OSMO_SOCK_F_CONNECT);
if (ret < 0) {
--
To view, visit https://gerrit.osmocom.org/10647
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I36344805a825f5d0e0c9d218d438d8fd985ed9ca
Gerrit-Change-Number: 10647
Gerrit-PatchSet: 2
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Stefan Sperling <ssperling at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180904/9140e619/attachment.htm>