From: relan Date: Fri, 25 Jan 2013 19:07:05 +0000 (+0000) Subject: Fix unexpected removal of a directory if it is moved into itself. X-Git-Tag: android-x86-6.0-r1~112 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3869d4b630b963a72c7cfe90612b71c3a4b0e118;p=android-x86%2Fexternal-exfat.git Fix unexpected removal of a directory if it is moved into itself. Return EINVAL in this situation. It also happens when trying to change directory name case. --- diff --git a/libexfat/node.c b/libexfat/node.c index cce1de7..bc342b7 100644 --- a/libexfat/node.c +++ b/libexfat/node.c @@ -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 */