On Friday, 3 July 2026 15:25:28 CEST Peter Maydell wrote: > 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; > + }
Officially only -1 is an invalid file descriptor, and if you look at this file we therefore check file descriptors exactly against -1 for that reason. For the Linux kernel the entire negative range is invalid for file descriptors, but keep in mind that 9pfs in QEMU also supports FreeBSD and macOS hosts and we have Windows host patches lurking around where things are not for certain, at least not for me. So I would not break that assumption. You might also consider adding error_report_once() in local_fid_fd() as this would be an unexpected case, even though gracefully handled already. /Christian
