Handle trailing slashes in source filenames correctly. E.g., rewrite

`mv foo/ ../..' to `mv foo/ ../../foo/', not to `mv foo/ ../../'.  The
latter caused a panic.  Before the trailing slash changes in the kernel,
the trailing slashes caused the rename() for this mv to fail earlier, so
there was no panic in 2.0.

Fixes part of PR 760.
This commit is contained in:
bde 1995-10-07 10:42:48 +00:00
parent f2884203e7
commit e9c97c811b

View File

@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: mv.c,v 1.2 1994/09/24 02:56:07 davidg Exp $
*/
#ifndef lint
@ -116,10 +116,16 @@ endarg: argc -= optind;
*endp++ = '/';
++baselen;
for (rval = 0; --argc; ++argv) {
if ((p = strrchr(*argv, '/')) == NULL)
p = *argv;
else
++p;
/*
* Find the last component of the source pathname. It
* may have trailing slashes.
*/
p = *argv + strlen(*argv);
while (p != *argv && p[-1] == '/')
--p;
while (p != *argv && p[-1] != '/')
--p;
if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
warnx("%s: destination pathname too long", *argv);
rval = 1;