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