From ebcfc3cc62d70956ba91946189cd7c41ebc1d764 Mon Sep 17 00:00:00 2001 From: Andrei Tatar Date: Tue, 18 Mar 2025 17:48:20 +0100 Subject: [PATCH] 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 --- lib/posix-fdio/fd-shim.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); -- 2.39.5