fixup_path_case() opens the final path component without O_DIRECTORY
and thus fails with -EISDIR if that component is a directory.

The only user so far resolved a file and called fstat() on the fd,
but in future we may extend it to handle directories as well,
so prepare for that.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 lib/libfile.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index bd0118a7e5be..35ec631de82f 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -869,7 +869,12 @@ int fixup_path_case(int fd, const char **path)
                free(imatch);
 
 next_component:
-               fd = openat(fd, curr, next ? O_DIRECTORY : 0);
+               /*
+                * The final component may be a directory as well, which
+                * can't be opened without O_DIRECTORY, but O_PATH suffices
+                * for the fstat() callers usually follow up with.
+                */
+               fd = openat(fd, curr, next ? O_DIRECTORY : O_PATH);
                closedir(dir);
 
                if (fd < 0)
-- 
2.47.3


Reply via email to