]> git.saurik.com Git - apple/file_cmds.git/blobdiff - rm/rm.c
file_cmds-264.50.1.tar.gz
[apple/file_cmds.git] / rm / rm.c
diff --git a/rm/rm.c b/rm/rm.c
index 4e78b46f24f4635ba107ac5947ecf7c705539236..ec13b2a4f50f05ac787ddcb42cf655b00b00743a 100644 (file)
--- a/rm/rm.c
+++ b/rm/rm.c
@@ -530,10 +530,24 @@ checkdot(argv)
 
        complained = 0;
        for (t = argv; *t;) {
 
        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;
                        p = *t;
+               }
                if (ISDOT(p)) {
                        if (!complained++)
                                warnx("\".\" and \"..\" may not be removed");
                if (ISDOT(p)) {
                        if (!complained++)
                                warnx("\".\" and \"..\" may not be removed");