stat: Fix chmod

Submitted by Zhang Tianci on Feb. 19, 2020, 2:32 a.m.

Details

Message ID 20200219023222.35095-1-zhangtianci1@huawei.com
State New
Series "stat: Fix chmod"
Headers show

Commit Message

Zhang Tianci Feb. 19, 2020, 2:32 a.m.
chmod misses `flag` argument when calling the syscall fchmodat.
Although Linux does not use `flag` in fchmodat, but in other system,
fchmodat will get a random value and it will cause flag check error.

Signed-off-by: Zhang Tianci <zhangtianci1@huawei.com>
---
 src/stat/chmod.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/stat/chmod.c b/src/stat/chmod.c
index d4f53c5..e99a146 100644
--- a/src/stat/chmod.c
+++ b/src/stat/chmod.c
@@ -7,6 +7,6 @@  int chmod(const char *path, mode_t mode)
 #ifdef SYS_chmod
 	return syscall(SYS_chmod, path, mode);
 #else
-	return syscall(SYS_fchmodat, AT_FDCWD, path, mode);
+	return syscall(SYS_fchmodat, AT_FDCWD, path, mode, 0);
 #endif
 }

Comments

Rich Felker Feb. 19, 2020, 3:50 a.m.
On Wed, Feb 19, 2020 at 10:32:22AM +0800, Zhang Tianci wrote:
> chmod misses `flag` argument when calling the syscall fchmodat.
> Although Linux does not use `flag` in fchmodat, but in other system,
> fchmodat will get a random value and it will cause flag check error.
> 
> Signed-off-by: Zhang Tianci <zhangtianci1@huawei.com>
> ---
>  src/stat/chmod.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/stat/chmod.c b/src/stat/chmod.c
> index d4f53c5..e99a146 100644
> --- a/src/stat/chmod.c
> +++ b/src/stat/chmod.c
> @@ -7,6 +7,6 @@ int chmod(const char *path, mode_t mode)
>  #ifdef SYS_chmod
>  	return syscall(SYS_chmod, path, mode);
>  #else
> -	return syscall(SYS_fchmodat, AT_FDCWD, path, mode);
> +	return syscall(SYS_fchmodat, AT_FDCWD, path, mode, 0);
>  #endif
>  }
> -- 
> 2.17.1

The Linux fchmodat syscall does not take a flags argument, which is
why src/stat/fchmodat.c has to go to such trouble to emulate one. It's
probably a mistake (but harmless) that we pass one (always zero) in
the first line:

        if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag);

It'd be nice if Linux would add new versions of this and faccessat
that take flags like they're supposed to.

Rich