Avoid truncating the pathname to UNIX Domain Sockets with snprintf(),

giving a more sensible warning when the (relatively meagre) sun_path
limit is exceeded.
This commit is contained in:
Tim J. Robbins 2002-06-29 04:52:33 +00:00
parent 87e1503e2c
commit 88485b4a2f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=99022

View File

@ -278,8 +278,11 @@ udom_open(const char *path, int flags)
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd >= 0) {
sou.sun_family = AF_UNIX;
snprintf(sou.sun_path, sizeof(sou.sun_path), "%s", path);
len = strlen(sou.sun_path);
if ((len = strlcpy(sou.sun_path, path,
sizeof(sou.sun_path))) >= sizeof(sou.sun_path)) {
errno = ENAMETOOLONG;
return (-1);
}
len = offsetof(struct sockaddr_un, sun_path[len+1]);
if (connect(fd, (void *)&sou, len) < 0) {