The local_fid_fd() function can fail (returning -1 if dirfd() fails); check for this explicitly rather than relying on something later on failing because it was passed a -1 file descriptor.
This was flagged up by Coverity: CID 1660923, 1660924, 1660925 Signed-off-by: Peter Maydell <[email protected]> --- hw/9pfs/9p-local.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index ee592b62f8..8f27c562b5 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -788,6 +788,9 @@ static int local_fstat(FsContext *fs_ctx, int fid_type, { int err, fd = local_fid_fd(fid_type, fs); + if (fd < 0) { + return fd; + } err = fstat(fd, stbuf); if (err) { return err; @@ -1055,6 +1058,9 @@ static int local_ftruncate(FsContext *ctx, int fid_type, V9fsFidOpenState *fs, { int fd = local_fid_fd(fid_type, fs); + if (fd < 0) { + return fd; + } return ftruncate(fd, size); } @@ -1113,6 +1119,9 @@ static int local_futimens(FsContext *s, int fid_type, V9fsFidOpenState *fs, { int fd = local_fid_fd(fid_type, fs); + if (fd < 0) { + return fd; + } return qemu_futimens(fd, times); } @@ -1196,6 +1205,9 @@ static int local_fsync(FsContext *ctx, int fid_type, { int fd = local_fid_fd(fid_type, fs); + if (fd < 0) { + return fd; + } if (datasync) { return qemu_fdatasync(fd); } else { -- 2.43.0
