summaryrefslogtreecommitdiff
path: root/sysdep/unix/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep/unix/io.c')
-rw-r--r--sysdep/unix/io.c10
1 files changed, 7 insertions, 3 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;