aboutsummaryrefslogtreecommitdiff
path: root/hw/9pfs
diff options
context:
space:
mode:
authorMalahal Naineni <malahal@us.ibm.com>2011-06-01 12:35:11 +0530
committerVenkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>2011-06-01 10:23:33 -0700
commit936532a4928ce6c95de5718974f6c987aaad7b68 (patch)
tree5a4a319004026198c64614052ae1977c23e96cbe /hw/9pfs
parent578c7b2ca8ee9e97fa8693b1a83d517e8e3f962e (diff)
[virtio-9p] Stop renaming files with similar name!
v9fs_complete_rename() mistakenly renames files with similar name as we don't check if the matched name is really an offspring. Signed-off-by: Malahal Naineni <malahal@us.ibm.com> Signed-off-by: Venkateswararao Jujjuri (JV) <jvrao@linux.vnet.ibm.com>
Diffstat (limited to 'hw/9pfs')
-rw-r--r--hw/9pfs/virtio-9p.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index b5fc52b3eb..77d1c0874a 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -423,6 +423,22 @@ static void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
v9fs_string_sprintf(lhs, "%s", rhs->data);
}
+/*
+ * Return TRUE if s1 is an ancestor of s2.
+ *
+ * E.g. "a/b" is an ancestor of "a/b/c" but not of "a/bc/d".
+ * As a special case, We treat s1 as ancestor of s2 if they are same!
+ */
+static int v9fs_path_is_ancestor(V9fsString *s1, V9fsString *s2)
+{
+ if (!strncmp(s1->data, s2->data, s1->size)) {
+ if (s2->data[s1->size] == '\0' || s2->data[s1->size] == '/') {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static size_t v9fs_string_size(V9fsString *str)
{
return str->size;
@@ -2805,13 +2821,13 @@ static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs)
for (fidp = s->fid_list; fidp; fidp = fidp->next) {
if (vs->fidp == fidp) {
/*
- * we replace name of this fid towards the end
- * so that our below strcmp will work
+ * we replace name of this fid towards the end so
+ * that our below v9fs_path_is_ancestor check will
+ * work
*/
continue;
}
- if (!strncmp(vs->fidp->path.data, fidp->path.data,
- strlen(vs->fidp->path.data))) {
+ if (v9fs_path_is_ancestor(&vs->fidp->path, &fidp->path)) {
/* replace the name */
v9fs_fix_path(&fidp->path, &vs->name,
strlen(vs->fidp->path.data));