]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: Ensure consistent and robust path checks
authorKarel Zak <kzak@redhat.com>
Tue, 13 Jan 2026 12:52:41 +0000 (13:52 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 13 Jan 2026 12:52:41 +0000 (13:52 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/path.c

index 7edc2079bfc4c47066727298dc0367c8d6d8a32a..674f74fd2f90bdd539150d3ad5895e5106df969e 100644 (file)
@@ -313,7 +313,7 @@ int ul_path_access(struct path_cxt *pc, int mode, const char *path)
                int dir = ul_path_get_dirfd(pc);
                if (dir < 0)
                        return dir;
-               if (*path == '/')
+               if (path && *path == '/')
                        path++;
 
                rc = faccessat(dir, path, mode, 0);
@@ -400,10 +400,8 @@ int ul_path_statx(struct path_cxt *pc, struct statx *stx, int flags, unsigned in
                int dir = ul_path_get_dirfd(pc);
                if (dir < 0)
                        return dir;
-               if (path) {
-                       if (*path == '/')
-                               path++;
-               }
+               if (path && *path == '/')
+                       path++;
 
                rc = statx(dir, path, flags, mask, stx);
        }