aboutsummaryrefslogtreecommitdiff
path: root/bin/cat/cat.c
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-06-29 04:52:33 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-06-29 04:52:33 +0000
commit88485b4a2fbfbfd17bd5e9896095c81f8a262c22 (patch)
tree9acc7ef1f3f385e7bc99f09a1da028f2bb2a9126 /bin/cat/cat.c
parent87e1503e2c698d43ddfa8cfaa72be34ea588293d (diff)
downloadsrc-88485b4a2fbfbfd17bd5e9896095c81f8a262c22.tar.gz
src-88485b4a2fbfbfd17bd5e9896095c81f8a262c22.zip
Avoid truncating the pathname to UNIX Domain Sockets with snprintf(),
giving a more sensible warning when the (relatively meagre) sun_path limit is exceeded.
Notes
Notes: svn path=/head/; revision=99022
Diffstat (limited to 'bin/cat/cat.c')
-rw-r--r--bin/cat/cat.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/cat/cat.c b/bin/cat/cat.c
index 3ea05de7939f..3d626f684aaa 100644
--- a/bin/cat/cat.c
+++ b/bin/cat/cat.c
@@ -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) {