summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoravsm <>2003-07-07 14:12:18 +0000
committeravsm <>2003-07-07 14:12:18 +0000
commitd288b2fefd42f6c13dc4f5fb684823316c61e5de (patch)
tree8fde4630632abd2c09aabe3d460748b2abd8a072
parent0fddbd33f24f3990d169df21977e93f6de42eda3 (diff)
downloadopenbsd-d288b2fefd42f6c13dc4f5fb684823316c61e5de.tar.gz
openbsd-d288b2fefd42f6c13dc4f5fb684823316c61e5de.tar.bz2
openbsd-d288b2fefd42f6c13dc4f5fb684823316c61e5de.zip
in the unix domain socket case, give an ENAMETOOLONG error instead of
silently truncating the socket file millert@ ok
-rw-r--r--src/usr.bin/nc/netcat.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index 84f131091a..8e02196c3a 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.59 2003/06/26 21:59:11 deraadt Exp $ */ 1/* $OpenBSD: netcat.c,v 1.60 2003/07/07 14:12:18 avsm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -377,7 +377,13 @@ unix_connect(char *path)
377 377
378 memset(&sun, 0, sizeof(struct sockaddr_un)); 378 memset(&sun, 0, sizeof(struct sockaddr_un));
379 sun.sun_family = AF_UNIX; 379 sun.sun_family = AF_UNIX;
380 strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); 380
381 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
382 sizeof(sun.sun_path)) {
383 close(s);
384 errno = ENAMETOOLONG;
385 return (-1);
386 }
381 if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { 387 if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
382 close(s); 388 close(s);
383 return (-1); 389 return (-1);
@@ -400,8 +406,16 @@ unix_listen(char *path)
400 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) 406 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
401 return (-1); 407 return (-1);
402 408
403 strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); 409 memset(&sun, 0, sizeof(struct sockaddr_un));
404 sun.sun_family = AF_UNIX; 410 sun.sun_family = AF_UNIX;
411
412 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
413 sizeof(sun.sun_path)) {
414 close(s);
415 errno = ENAMETOOLONG;
416 return (-1);
417 }
418
405 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { 419 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
406 close(s); 420 close(s);
407 return (-1); 421 return (-1);