[PATCH v8] posix: Deprecate group_member for Linux
Paul Eggert
eggert@cs.ucla.edu
Tue Mar 26 17:00:55 GMT 2024
The change to faccessat.c (quoted below) is problematic, as it could
entail multiple calls to getegid or to getgid, with inconsistent results
if some other thread is changing the group id of the current process.
Instead, I suggest declaring "granted" via a simple "int granted;" and
then using an if statement to initialize it, so that the logic is not
duplicated and the multiple calls eliminated.
> --- a/sysdeps/unix/sysv/linux/faccessat.c
> +++ b/sysdeps/unix/sysv/linux/faccessat.c
> @@ -59,11 +59,17 @@ __faccessat (int fd, const char *file, int mode, int flag)
> || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
> return 0;
>
> + int gm = __group_member2 (stats.st_gid);
> + if (uid != stats.st_uid &&
> + (stats.st_gid != ((flag & AT_EACCESS) ? __getegid () : __getgid ())))
> + if (gm == -1)
> + return -1;
> +
> int granted = (uid == stats.st_uid
> ? (unsigned int) (stats.st_mode & (mode << 6)) >> 6
> : (stats.st_gid == ((flag & AT_EACCESS)
> ? __getegid () : __getgid ())
> - || __group_member (stats.st_gid))
> + || gm)
> ? (unsigned int) (stats.st_mode & (mode << 3)) >> 3
> : (stats.st_mode & mode));
>
More information about the Libc-alpha
mailing list