9pfs: fix name_to_path assertion in v9fs_complete_rename()

The third parameter of v9fs_co_name_to_path() must not contain `/'
character.

The issue is most likely related to 9p2000.u protocol only.

Signed-off-by: Jan Dakinevich <jan.dakinevich@gmail.com>
[groug, regression caused by commit f57f587857 # 2.10]
Signed-off-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
Jan Dakinevich 2017-09-20 08:48:52 +02:00 committed by Greg Kurz
parent 6069537f43
commit 4d8bc7334b
1 changed files with 9 additions and 14 deletions

View File

@ -2553,13 +2553,11 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp,
int32_t newdirfid, int32_t newdirfid,
V9fsString *name) V9fsString *name)
{ {
char *end;
int err = 0; int err = 0;
V9fsPath new_path; V9fsPath new_path;
V9fsFidState *tfidp; V9fsFidState *tfidp;
V9fsState *s = pdu->s; V9fsState *s = pdu->s;
V9fsFidState *dirfidp = NULL; V9fsFidState *dirfidp = NULL;
char *old_name, *new_name;
v9fs_path_init(&new_path); v9fs_path_init(&new_path);
if (newdirfid != -1) { if (newdirfid != -1) {
@ -2577,18 +2575,15 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp,
goto out; goto out;
} }
} else { } else {
old_name = fidp->path.data; char *dir_name = g_path_get_dirname(fidp->path.data);
end = strrchr(old_name, '/'); V9fsPath dir_path;
if (end) {
end++; v9fs_path_init(&dir_path);
} else { v9fs_path_sprintf(&dir_path, "%s", dir_name);
end = old_name; g_free(dir_name);
}
new_name = g_malloc0(end - old_name + name->size + 1); err = v9fs_co_name_to_path(pdu, &dir_path, name->data, &new_path);
strncat(new_name, old_name, end - old_name); v9fs_path_free(&dir_path);
strncat(new_name + (end - old_name), name->data, name->size);
err = v9fs_co_name_to_path(pdu, NULL, new_name, &new_path);
g_free(new_name);
if (err < 0) { if (err < 0) {
goto out; goto out;
} }