mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
vfs: shave a branch in getname_flags
Check for an error while copying and no path in one branch. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://lore.kernel.org/r/20240604155257.109500-4-mjguzik@gmail.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
dff60734fc
commit
d4f50ea957
31
fs/namei.c
31
fs/namei.c
@ -148,9 +148,20 @@ getname_flags(const char __user *filename, int flags)
|
||||
result->name = kname;
|
||||
|
||||
len = strncpy_from_user(kname, filename, EMBEDDED_NAME_MAX);
|
||||
if (unlikely(len < 0)) {
|
||||
__putname(result);
|
||||
return ERR_PTR(len);
|
||||
/*
|
||||
* Handle both empty path and copy failure in one go.
|
||||
*/
|
||||
if (unlikely(len <= 0)) {
|
||||
if (unlikely(len < 0)) {
|
||||
__putname(result);
|
||||
return ERR_PTR(len);
|
||||
}
|
||||
|
||||
/* The empty path is special. */
|
||||
if (!(flags & LOOKUP_EMPTY)) {
|
||||
__putname(result);
|
||||
return ERR_PTR(-ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -180,6 +191,12 @@ getname_flags(const char __user *filename, int flags)
|
||||
kfree(result);
|
||||
return ERR_PTR(len);
|
||||
}
|
||||
/* The empty path is special. */
|
||||
if (unlikely(!len) && !(flags & LOOKUP_EMPTY)) {
|
||||
__putname(kname);
|
||||
kfree(result);
|
||||
return ERR_PTR(-ENOENT);
|
||||
}
|
||||
if (unlikely(len == PATH_MAX)) {
|
||||
__putname(kname);
|
||||
kfree(result);
|
||||
@ -188,14 +205,6 @@ getname_flags(const char __user *filename, int flags)
|
||||
}
|
||||
|
||||
atomic_set(&result->refcnt, 1);
|
||||
/* The empty path is special. */
|
||||
if (unlikely(!len)) {
|
||||
if (!(flags & LOOKUP_EMPTY)) {
|
||||
putname(result);
|
||||
return ERR_PTR(-ENOENT);
|
||||
}
|
||||
}
|
||||
|
||||
result->uptr = filename;
|
||||
result->aname = NULL;
|
||||
audit_getname(result);
|
||||
|
Loading…
Reference in New Issue
Block a user