Bug 507868

Summary: futimesat doesn't handle AT_FDCWD
Product: [Developer tools] valgrind Reporter: Mark Wielaard <mark>
Component: generalAssignee: mcermak
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 3.25 GIT   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Bug Depends on:    
Bug Blocks: 506971    
Attachments: proposed patch
proposed patch
proposed patch

Description Mark Wielaard 2025-08-04 21:48:21 UTC
Like other "at" syscalls fd can have the special value AT_FDCWD which is an "invalid file descriptor".

The LTP futimesat01 testcase shows:

==695142== Warning: invalid file descriptor -100 in syscall futimesat()
futimesat01    5  TFAIL  :  futimesat01.c:85: futimesat() failed: TEST_ERRNO=EBADF(9): Bad file descriptor

There is no LTP testcase for it, but if pathname is absolute, then fd is ignored.
Comment 1 mcermak 2025-08-05 12:58:08 UTC
Created attachment 183803 [details]
proposed patch
Comment 2 mcermak 2025-08-05 13:33:08 UTC
Created attachment 183805 [details]
proposed patch
Comment 3 mcermak 2025-08-05 14:56:04 UTC
Created attachment 183808 [details]
proposed patch
Comment 4 Mark Wielaard 2025-08-06 17:24:08 UTC
(In reply to mcermak from comment #3)
> Created attachment 183808 [details]
> proposed patch

Looks good. Pushed as:

commit bdbce5686e4204d678814fa861d153c5bc5252f8
Author: Martin Cermak <mcermak@redhat.com>
Date:   Tue Aug 5 16:54:54 2025 +0200

    The futimesat syscall wrapper doesn't handle AT_FDCWD
    
    Update futimesat syscall wrapper so that it doesn't consider the
    special value AT_FDCWD (-100) an invalid file descriptor.
    
    https://bugs.kde.org/show_bug.cgi?id=507868