All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/9pfs: Check for error return from local_fid_fd()
@ 2026-07-03 13:25 Peter Maydell
  2026-07-03 13:52 ` Michael Tokarev
  2026-07-03 16:22 ` Christian Schoenebeck
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Maydell @ 2026-07-03 13:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Christian Schoenebeck, Greg Kurz

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 <peter.maydell@linaro.org>
---
 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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-03 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 13:25 [PATCH] hw/9pfs: Check for error return from local_fid_fd() Peter Maydell
2026-07-03 13:52 ` Michael Tokarev
2026-07-03 14:03   ` Peter Maydell
2026-07-03 16:22 ` Christian Schoenebeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.