mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-15 13:15:57 +00:00
hostfs: fix string handling in __dentry_name()
strcpy() should not be used with destination potentially overlapping the source; what's more, strscpy() in there is pointless - we already know the amount we want to copy; might as well use memcpy(). Fixes: c278e81b8a02 "hostfs: Remove open coded strcpy()" Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
40384c840e
commit
60a6002432
@ -95,32 +95,17 @@ __uml_setup("hostfs=", hostfs_args,
|
|||||||
static char *__dentry_name(struct dentry *dentry, char *name)
|
static char *__dentry_name(struct dentry *dentry, char *name)
|
||||||
{
|
{
|
||||||
char *p = dentry_path_raw(dentry, name, PATH_MAX);
|
char *p = dentry_path_raw(dentry, name, PATH_MAX);
|
||||||
char *root;
|
struct hostfs_fs_info *fsi = dentry->d_sb->s_fs_info;
|
||||||
size_t len;
|
char *root = fsi->host_root_path;
|
||||||
struct hostfs_fs_info *fsi;
|
size_t len = strlen(root);
|
||||||
|
|
||||||
fsi = dentry->d_sb->s_fs_info;
|
if (IS_ERR(p) || len > p - name) {
|
||||||
root = fsi->host_root_path;
|
|
||||||
len = strlen(root);
|
|
||||||
if (IS_ERR(p)) {
|
|
||||||
__putname(name);
|
__putname(name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
memcpy(name, root, len);
|
||||||
* This function relies on the fact that dentry_path_raw() will place
|
memmove(name + len, p, name + PATH_MAX - p);
|
||||||
* the path name at the end of the provided buffer.
|
|
||||||
*/
|
|
||||||
BUG_ON(p + strlen(p) + 1 != name + PATH_MAX);
|
|
||||||
|
|
||||||
strscpy(name, root, PATH_MAX);
|
|
||||||
if (len > p - name) {
|
|
||||||
__putname(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p > name + len)
|
|
||||||
strcpy(name + len, p);
|
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user