From 27e79e1d84c12731f2573b35eaf9839ff45ef082 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sat, 7 Oct 1995 10:42:48 +0000 Subject: [PATCH] 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. --- bin/mv/mv.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 05530804b25..91217d3563a 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -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;