OSDN Git Service

Fixed crash in exfat_rename() when renaming a file within a single directory and...
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 15 Dec 2012 08:51:09 +0000 (08:51 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 15 Dec 2012 08:51:09 +0000 (08:51 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@310 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/node.c

index 5b43a3a..307f2ec 100644 (file)
@@ -910,27 +910,33 @@ int exfat_rename(struct exfat* ef, const char* old_path, const char* new_path)
        }
        if (existing != NULL)
        {
-               if (existing->flags & EXFAT_ATTRIB_DIR)
+               /* remove target if it's not the same node as source */
+               if (existing != node)
                {
-                       if (node->flags & EXFAT_ATTRIB_DIR)
-                               rc = exfat_rmdir(ef, existing);
+                       if (existing->flags & EXFAT_ATTRIB_DIR)
+                       {
+                               if (node->flags & EXFAT_ATTRIB_DIR)
+                                       rc = exfat_rmdir(ef, existing);
+                               else
+                                       rc = -ENOTDIR;
+                       }
                        else
-                               rc = -ENOTDIR;
+                       {
+                               if (!(node->flags & EXFAT_ATTRIB_DIR))
+                                       rc = exfat_unlink(ef, existing);
+                               else
+                                       rc = -EISDIR;
+                       }
+                       exfat_put_node(ef, existing);
+                       if (rc != 0)
+                       {
+                               exfat_put_node(ef, dir);
+                               exfat_put_node(ef, node);
+                               return rc;
+                       }
                }
                else
-               {
-                       if (!(node->flags & EXFAT_ATTRIB_DIR))
-                               rc = exfat_unlink(ef, existing);
-                       else
-                               rc = -EISDIR;
-               }
-               exfat_put_node(ef, existing);
-               if (rc != 0)
-               {
-                       exfat_put_node(ef, dir);
-                       exfat_put_node(ef, node);
-                       return rc;
-               }
+                       exfat_put_node(ef, existing);
        }
 
        rc = find_slot(ef, dir, &cluster, &offset,