diff options
author | 2005-04-15 00:51:57 +0000 | |
---|---|---|
committer | 2005-04-15 00:51:57 +0000 | |
commit | 98b1b233dc3013673e13003406f2bb53e80e18f0 (patch) | |
tree | 9ca75a81a2fffce76acf128c37af75418f046744 /bin/ln | |
parent | print proper model string. (diff) | |
download | wireguard-openbsd-98b1b233dc3013673e13003406f2bb53e80e18f0.tar.xz wireguard-openbsd-98b1b233dc3013673e13003406f2bb53e80e18f0.zip |
check snprintf return value and abort if the concatenated path is too
long instead of using the truncated path. also, use the strerror()
database instead of repeating the text here.
ok krw@, millert@
Diffstat (limited to 'bin/ln')
-rw-r--r-- | bin/ln/ln.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/bin/ln/ln.c b/bin/ln/ln.c index 180c514f265..697b98cdd8b 100644 --- a/bin/ln/ln.c +++ b/bin/ln/ln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ln.c,v 1.11 2004/12/17 00:36:07 jaredy Exp $ */ +/* $OpenBSD: ln.c,v 1.12 2005/04/15 00:51:57 uwe Exp $ */ /* $NetBSD: ln.c,v 1.10 1995/03/21 09:06:10 cgd Exp $ */ /* @@ -40,7 +40,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94"; #else -static const char rcsid[] = "$OpenBSD: ln.c,v 1.11 2004/12/17 00:36:07 jaredy Exp $"; +static const char rcsid[] = "$OpenBSD: ln.c,v 1.12 2005/04/15 00:51:57 uwe Exp $"; #endif #endif /* not lint */ @@ -121,6 +121,7 @@ linkit(char *target, char *source, int isdir) struct stat sb; char *p, path[MAXPATHLEN]; int (*statf)(const char *, struct stat *); + int n; if (!sflag) { /* If target doesn't exist, quit now. */ @@ -130,7 +131,8 @@ linkit(char *target, char *source, int isdir) } /* Only symbolic links to directories, unless -F option used. */ if (!dirflag && S_ISDIR(sb.st_mode)) { - warnx("%s: is a directory", target); + errno = EISDIR; + warn("%s", target); return (1); } } @@ -143,7 +145,12 @@ linkit(char *target, char *source, int isdir) warn("%s", target); return (1); } - (void)snprintf(path, sizeof(path), "%s/%s", source, p); + n = snprintf(path, sizeof(path), "%s/%s", source, p); + if (n < 0 || n >= sizeof(path)) { + errno = ENAMETOOLONG; + warn("%s/%s", source, p); + return (1); + } source = path; } |