OSDN Git Service

Fixed unexpected removal of a directory if it is moved into itself: return EINVAL...
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Fri, 25 Jan 2013 19:07:05 +0000 (19:07 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Fri, 25 Jan 2013 19:07:05 +0000 (19:07 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@337 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/node.c

index cce1de7..bc342b7 100644 (file)
@@ -905,6 +905,23 @@ int exfat_rename(struct exfat* ef, const char* old_path, const char* new_path)
                exfat_put_node(ef, node);
                return rc;
        }
+
+       /* check that target is not a subdirectory of the source */
+       if (node->flags & EXFAT_ATTRIB_DIR)
+       {
+               struct exfat_node* p;
+
+               for (p = dir; p; p = p->parent)
+                       if (node == p)
+                       {
+                               if (existing != NULL)
+                                       exfat_put_node(ef, existing);
+                               exfat_put_node(ef, dir);
+                               exfat_put_node(ef, node);
+                               return -EINVAL;
+                       }
+       }
+
        if (existing != NULL)
        {
                /* remove target if it's not the same node as source */