Date: Wed, 29 May 2002 01:52:20 +0300 (EEST) From: Giorgos Keramidas <keramida@FreeBSD.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/38671: Add a check for MAXPATHLEN to cp(1). Message-ID: <200205282252.g4SMqK8n057710@hades.hell.gr>
next in thread | raw e-mail | index | archive | help
>Number: 38671
>Category: bin
>Synopsis: Add a check for MAXPATHLEN to cp(1).
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue May 28 16:00:09 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Giorgos Keramidas
>Release: FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD hades.hell.gr 5.0-CURRENT FreeBSD 5.0-CURRENT #0:
Mon May 27 23:54:32 EEST 2002 root@hades.hell.gr:/usr/obj/usr/src/sys/HECATE i386
>Description:
The following patch has been merged from NetBSD. Their version of
cp(1) always checks the destination pathname to make sure it doesn't
exceed MAXPATHLEN.
>How-To-Repeat:
>Fix:
%%%
Index: cp.c
===================================================================
RCS file: /home/ncvs/src/bin/cp/cp.c,v
retrieving revision 1.35
diff -u -r1.35 cp.c
--- cp.c 17 May 2002 12:24:19 -0000 1.35
+++ cp.c 28 May 2002 21:25:22 -0000
@@ -172,6 +172,8 @@
/* Save the target base in "to". */
target = argv[--argc];
+ if (strlen(target) > MAXPATHLEN)
+ errx(1, "%s: name too long", target);
if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
errx(1, "%s: name too long", target);
to.p_end = to.p_path + strlen(to.p_path);
@@ -290,6 +292,14 @@
* source name to the target name.
*/
if (type != FILE_TO_FILE) {
+ if ((curr->fts_namelen +
+ to.target_end - to.p_path + 1) > MAXPATHLEN) {
+ warnx("%s/%s: name too long (not copied)",
+ to.p_path, curr->fts_name);
+ rval = 1;
+ continue;
+ }
+
/*
* Need to remember the roots of traversals to create
* correct pathnames. If there's a directory being
%%%
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205282252.g4SMqK8n057710>
