Skip to content
Permalink
Browse files
cifs: sanitize multiple delimiters in prepath
mount.cifs can pass a device with multiple delimiters in it. This will
cause rename(2) to fail with ENOENT.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2031200
Signed-off-by: Thiago Rafael Becker <trbecker@gmail.com>
  • Loading branch information
trbecker authored and intel-lab-lkp committed Dec 15, 2021
1 parent 9de0737 commit e81ed85a4288e898bc0607106d98905be5cd3788
Showing 1 changed file with 30 additions and 0 deletions.
@@ -434,6 +434,34 @@ int smb3_parse_opt(const char *options, const char *key, char **val)
return rc;
}

/*
* remove duplicate path delimiters. Windows is supposed to do that
* but there are some bugs that prevent rename from working if there are
* multiple delimiters.
*/
void sanitize_path(char *path) {
char *pos = path, last = *path;
unsigned int offset = 0;

while(*(++pos)) {
if ((*pos == '/' || *pos == '\\') && (last == '/' || last == '\\')) {
offset++;
continue;
}

last = *pos;
*(pos - offset) = *pos;
}

pos = pos - offset - 1;

/* At this point, there should be only zero or one delimiter at the end of the string */
if (*pos != '/' && *pos != '\\')
pos++;

*pos = '\0';
}

/*
* Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
* fields with the result. Returns 0 on success and an error otherwise
@@ -497,6 +525,8 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
if (!ctx->prepath)
return -ENOMEM;

sanitize_path(ctx->prepath);

return 0;
}

0 comments on commit e81ed85

Please sign in to comment.