X-Git-Url: https://git.saurik.com/apple/file_cmds.git/blobdiff_plain/00337e45cbde0be25dd3e61cbd0bd3a55c65ab01..39aaa94bf0a1c68b3fe15e3622c96766f0f22ff2:/rm/rm.c?ds=sidebyside diff --git a/rm/rm.c b/rm/rm.c index 4e78b46..ec13b2a 100644 --- a/rm/rm.c +++ b/rm/rm.c @@ -530,10 +530,24 @@ checkdot(argv) complained = 0; for (t = argv; *t;) { - if ((p = strrchr(*t, '/')) != NULL) - ++p; - else + size_t len = strlen(*t); + char truncated[len]; + + if ((p = strrchr(*t, '/')) != NULL) { + if (p[1] == '\0') { // trailing / -- treat as if not present + strlcpy(truncated, *t, len); + p = strrchr(truncated, '/'); + if (p) { + ++p; + } else { + p = truncated; + } + } else { + ++p; + } + } else { p = *t; + } if (ISDOT(p)) { if (!complained++) warnx("\".\" and \"..\" may not be removed");