diff options
author | bde <bde@FreeBSD.org> | 1995-10-07 10:42:48 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1995-10-07 10:42:48 +0000 |
commit | c37d4b75ea14ae252198dabf64d99c7e01c74bb9 (patch) | |
tree | ac1ac6570dbf8460ac6a401a16be5ecd61e27336 | |
parent | 9674b45cfa0a7de8553d61513a462108c5f2e00b (diff) | |
download | FreeBSD-src-c37d4b75ea14ae252198dabf64d99c7e01c74bb9.zip FreeBSD-src-c37d4b75ea14ae252198dabf64d99c7e01c74bb9.tar.gz |
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.
-rw-r--r-- | bin/mv/mv.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 0553080..91217d3 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; |