Skip to content

unix rwx permissions are incorrectly extracted from the file mode bits in `access`

https://gitlab.redox-os.org/redox-os/relibc/-/blob/6d0f8d9bd7efb273a8beafdc046fde5cda33f075/src/platform/redox/mod.rs#L100 existing code:

        let perms = if stat.st_uid as usize == uid {
            stat.st_mode >> (3 * 2 & 0o7)
        } else if stat.st_gid as usize == gid {
            stat.st_mode >> (3 * 1 & 0o7)
        } else {
            stat.st_mode & 0o7
        };
        if (mode & R_OK == R_OK && perms & 0o4 != 0o4)
            || (mode & W_OK == W_OK && perms & 0o2 != 0o2)
            || (mode & X_OK == X_OK && perms & 0o1 != 0o1)
        {
            return Err(Errno(EINVAL));
        }

the correct way to extract from the mode bits is: (stat.st_mode >> 3 * <number>) & 7