]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdio: Fix missing error in fcntl(GETFD)
authorAndrei Tatar <andrei@unikraft.io>
Tue, 18 Mar 2025 16:48:20 +0000 (17:48 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 27 Mar 2025 17:23:26 +0000 (17:23 +0000)
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 <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1602

lib/posix-fdio/fd-shim.c

index 7fb073308772db3b450ca6ff499e20b012c8078c..687dfcb031925277ab6abf6608302dbdddcb328e 100644 (file)
@@ -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);