mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-29 21:12:07 -06:00
9p: local: always return -1 on error in local_unlinkat_common
local_unlinkat_common() is supposed to always return -1 on error. This is being done by jumps to the 'err_out' label, which is a 'return ret' call, and 'ret' is initialized with -1. Unfortunately there is a condition in which the function will return 0 on error: in a case where flags == AT_REMOVEDIR, 'ret' will be 0 when reaching map_dirfd = openat_dir(...) And, if map_dirfd == -1 and errno != ENOENT, the existing 'err_out' jump will execute 'return ret', when ret is still set to zero at that point. This patch fixes it by changing all 'err_out' labels by 'return -1' calls, ensuring that the function will always return -1 on error conditions. 'ret' can be left unintialized since it's now being used just to store the result of 'unlinkat' calls. CC: Greg Kurz <groug@kaod.org> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> [groug: changed prefix in title to be "9p: local:"] Signed-off-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
parent
841b8d099c
commit
846cf408a4
1 changed files with 6 additions and 8 deletions
|
@ -1076,7 +1076,7 @@ out:
|
||||||
static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
|
static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret;
|
||||||
|
|
||||||
if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
|
||||||
int map_dirfd;
|
int map_dirfd;
|
||||||
|
@ -1094,12 +1094,12 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
|
||||||
|
|
||||||
fd = openat_dir(dirfd, name);
|
fd = openat_dir(dirfd, name);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
goto err_out;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
|
ret = unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR);
|
||||||
close_preserve_errno(fd);
|
close_preserve_errno(fd);
|
||||||
if (ret < 0 && errno != ENOENT) {
|
if (ret < 0 && errno != ENOENT) {
|
||||||
goto err_out;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
|
map_dirfd = openat_dir(dirfd, VIRTFS_META_DIR);
|
||||||
|
@ -1107,16 +1107,14 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,
|
||||||
ret = unlinkat(map_dirfd, name, 0);
|
ret = unlinkat(map_dirfd, name, 0);
|
||||||
close_preserve_errno(map_dirfd);
|
close_preserve_errno(map_dirfd);
|
||||||
if (ret < 0 && errno != ENOENT) {
|
if (ret < 0 && errno != ENOENT) {
|
||||||
goto err_out;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (errno != ENOENT) {
|
} else if (errno != ENOENT) {
|
||||||
goto err_out;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = unlinkat(dirfd, name, flags);
|
return unlinkat(dirfd, name, flags);
|
||||||
err_out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int local_remove(FsContext *ctx, const char *path)
|
static int local_remove(FsContext *ctx, const char *path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue