Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Sep 2007 11:30:28 -0700
From:      LI Xin <delphij@delphij.net>
To:        freebsd-stable@FreeBSD.ORG,  torfinn.ingolfsen@broadpark.no
Subject:   Re: rm(1) bug, possibly serious
Message-ID:  <46F953C4.1030707@delphij.net>
In-Reply-To: <200709251743.l8PHhvlP012244@lurza.secnetix.de>
References:  <200709251743.l8PHhvlP012244@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig75FE4668FDDB8DE1C013E831
Content-Type: multipart/mixed; boundary="------------000106020508020706020709"

This is a multi-part message in MIME format.
--------------000106020508020706020709
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I think this is a bug, here is a fix obtained from NetBSD.

The reasoning (from NetBSD's rm.c,v 1.16):

Strip trailing slashes of operands in checkdot().

POSIX.2 requires that if "." or ".." are specified as the basename
portion of an operand, a diagnostic message be written to standard
error, etc.  We strip the slashes because POSIX.2 defines basename
as the final portion of a pathname after trailing slashes have been
removed.

This also makes rm "perform actions equivalent to" the POSIX.1
rmdir() and unlink() functions when removing directories and files,
even when they do not follow POSIX.1's pathname resolution semantics
(which require trailing slashes be ignored).

If nobody complains about this I will request for commit approval from re=
@.

Cheers,
--=20
Xin LI <delphij@delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!

--------------000106020508020706020709
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
	name="rm-posix.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="rm-posix.diff"

Index: rm.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/bin/rm/rm.c,v
retrieving revision 1.58
diff -u -p -r1.58 rm.c
--- rm.c	31 Oct 2006 02:22:36 -0000	1.58
+++ rm.c	25 Sep 2007 18:26:52 -0000
@@ -558,6 +558,14 @@ check2(char **argv)
 	return (first =3D=3D 'y' || first =3D=3D 'Y');
 }
=20
+/*
+ * POSIX.2 requires that if "." or ".." are specified as the basename
+ * portion of an operand, a diagnostic message be written to standard
+ * error and nothing more be done with such operands.
+ *
+ * Since POSIX.2 defines basename as the final portion of a path after
+ * trailing slashes have been removed, we'll remove them here.
+ */
 #define ISDOT(a)	((a)[0] =3D=3D '.' && (!(a)[1] || ((a)[1] =3D=3D '.' &&=
 !(a)[2])))
 void
 checkdot(char **argv)
@@ -567,10 +575,17 @@ checkdot(char **argv)
=20
 	complained =3D 0;
 	for (t =3D argv; *t;) {
+		/* strip trailing slashes */
+		p =3D strrchr(*t, '\0');
+		while (--p > *t && *p =3D=3D '/')
+			*p =3D '\0';
+
+		/* extract basename */
 		if ((p =3D strrchr(*t, '/')) !=3D NULL)
 			++p;
 		else
 			p =3D *t;
+
 		if (ISDOT(p)) {
 			if (!complained++)
 				warnx("\".\" and \"..\" may not be removed");

--------------000106020508020706020709--

--------------enig75FE4668FDDB8DE1C013E831
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG+VPFOfuToMruuMARCg5cAJ4o9qjqfuupAuXj4Zl2/E5qdxGXHQCgi68U
E9tNjSg+Y83rzdt3HU+mh5g=
=tjXg
-----END PGP SIGNATURE-----

--------------enig75FE4668FDDB8DE1C013E831--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46F953C4.1030707>