summaryrefslogtreecommitdiff
path: root/sysdep
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2020-08-29 12:41:23 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2021-01-12 23:34:17 +0100
commit0d2888fb4950d7b3f1e19237f80a16a2253b37ec (patch)
tree0cce00e85b6f8af8cda854ccf15620909be11888 /sysdep
parent42c826b49b3e879810b38669805e14f76c281685 (diff)
Unix: Support abstract socket in sk_unix_connect
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/unix/io.c10
-rw-r--r--sysdep/unix/unix.h2
2 files changed, 8 insertions, 4 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 3aba48d2..14bf99fe 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -1513,11 +1513,14 @@ sk_open_unix(sock *s, char *name)
}
int
-sk_connect_unix(sock *s, char *name)
+sk_connect_unix(sock *s, char *name, socklen_t namelen)
{
struct sockaddr_un sa;
int fd;
+ if (namelen > sizeof(sa.sun_path))
+ return -1;
+
/* We are sloppy during error (leak fd and not set s->err), but we die anyway */
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -1528,10 +1531,11 @@ sk_connect_unix(sock *s, char *name)
return -1;
/* Path length checked in test_old_bird() */
+ memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
- strcpy(sa.sun_path, name);
+ memcpy(sa.sun_path, name, namelen);
- if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0)
+ if (connect(fd, (struct sockaddr *) &sa, sizeof(sa.sun_family) + namelen) < 0)
return -1;
s->fd = fd;
diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h
index 849e5947..a95e5c25 100644
--- a/sysdep/unix/unix.h
+++ b/sysdep/unix/unix.h
@@ -108,7 +108,7 @@ void io_loop(void);
void io_log_dump(void);
int sk_open_unix(struct birdsock *s, char *name);
struct rfile *rf_open(struct pool *, const char *name, const char *mode);
-int sk_connect_unix(struct birdsock *s, char *name);
+int sk_connect_unix(struct birdsock *s, char *name, socklen_t namelen);
void *rf_file(struct rfile *f);
int rf_fileno(struct rfile *f);
void test_old_bird(char *path);