diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-03-13 22:17:05 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-03-13 22:17:05 +0000 |
commit | 14a08e5ed5cb4134c808a91838edfc3aaab79a3d (patch) | |
tree | af55b64d67b0e168e27efed1ee34cd1d0cc57751 | |
parent | 0b558c1deaad0d73d956a56c2ead5efd29fe3e8a (diff) |
Use the return value of strcpy() to detect ENAMETOOLONG instead of
doing an extra strlen; deraadt@ OK
-rw-r--r-- | bin/cp/cp.c | 7 | ||||
-rw-r--r-- | bin/mv/mv.c | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c index ee8e50b7cea..0daa7019414 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cp.c,v 1.22 2003/03/13 09:09:20 deraadt Exp $ */ +/* $OpenBSD: cp.c,v 1.23 2003/03/13 22:17:04 millert Exp $ */ /* $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -static char rcsid[] = "$OpenBSD: cp.c,v 1.22 2003/03/13 09:09:20 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cp.c,v 1.23 2003/03/13 22:17:04 millert Exp $"; #endif #endif /* not lint */ @@ -186,9 +186,8 @@ main(int argc, char *argv[]) /* Save the target base in "to". */ target = argv[--argc]; - if (strlen(target) >= sizeof(to.p_path)) + if (strlcpy(to.p_path, target, sizeof to.p_path) >= sizeof(to.p_path)) errx(1, "%s: name too long", target); - (void)strlcpy(to.p_path, target, sizeof to.p_path); to.p_end = to.p_path + strlen(to.p_path); if (to.p_path == to.p_end) { *to.p_end++ = '.'; diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 059fff2ba7d..ae83c1921f8 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mv.c,v 1.25 2003/03/13 09:09:24 deraadt Exp $ */ +/* $OpenBSD: mv.c,v 1.26 2003/03/13 22:17:04 millert Exp $ */ /* $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: mv.c,v 1.25 2003/03/13 09:09:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mv.c,v 1.26 2003/03/13 22:17:04 millert Exp $"; #endif #endif /* not lint */ @@ -120,9 +120,8 @@ main(int argc, char *argv[]) } /* It's a directory, move each file into it. */ - if (strlen(argv[argc - 1]) > sizeof path - 1) + if (strlcpy(path, argv[argc - 1], sizeof path) >= sizeof path) errx(1, "%s: destination pathname too long", *argv); - (void)strlcpy(path, argv[argc - 1], sizeof path); baselen = strlen(path); endp = &path[baselen]; if (*(endp - 1) != '/') { |