From: Andrei Tatar Date: Tue, 18 Mar 2025 16:48:20 +0000 (+0100) Subject: lib/posix-fdio: Fix missing error in fcntl(GETFD) X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ebcfc3cc62d70956ba91946189cd7c41ebc1d764;p=unikraft%2Funikraft.git lib/posix-fdio: Fix missing error in fcntl(GETFD) This change fixes a bug where fcntl(F_GETFD) would swallow error codes from uk_fdtab_getflags and not return them up the callstack. Signed-off-by: Andrei Tatar Approved-by: Sergiu Moga Reviewed-by: Sergiu Moga GitHub-Closes: #1602 --- diff --git a/lib/posix-fdio/fd-shim.c b/lib/posix-fdio/fd-shim.c index 7fb073308..687dfcb03 100644 --- a/lib/posix-fdio/fd-shim.c +++ b/lib/posix-fdio/fd-shim.c @@ -499,7 +499,10 @@ UK_LLSYSCALL_R_DEFINE(int, fcntl, int, fd, case F_DUPFD: return uk_sys_dup_min(fd, (int)arg, fdflags); case F_GETFD: - return (uk_fdtab_getflags(fd) & O_CLOEXEC) ? FD_CLOEXEC : 0; + fdflags = uk_fdtab_getflags(fd); + if (unlikely(fdflags < 0)) + return fdflags; + return (fdflags & O_CLOEXEC) ? FD_CLOEXEC : 0; case F_SETFD: return uk_fdtab_setflags(fd, ((int)arg & FD_CLOEXEC) ? O_CLOEXEC : 0);