From b630d12333b002ede0f8c8e5a10ea96d10036c2d Mon Sep 17 00:00:00 2001 From: resver Date: Sat, 15 Dec 2012 08:51:09 +0000 Subject: [PATCH] Fixed crash in exfat_rename() when renaming a file within a single directory and a new name differs only in case. git-svn-id: http://exfat.googlecode.com/svn/trunk@310 60bc1c72-a15a-11de-b98f-4500b42dc123 --- libexfat/node.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/libexfat/node.c b/libexfat/node.c index 5b43a3a..307f2ec 100644 --- a/libexfat/node.c +++ b/libexfat/node.c @@ -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, -- 2.11.0