diff mbox series

syscalls/chdir: bugfix for syscalls/chdir/chdir01.c

Message ID 20210322091512.103266-1-xieziyao@huawei.com
State Accepted
Headers show
Series syscalls/chdir: bugfix for syscalls/chdir/chdir01.c | expand

Commit Message

Xie Ziyao March 22, 2021, 9:15 a.m. UTC
Add umask(0) before SAFE_MKDIR(DIR_NAME, 0755) to prevent the unexpected case failure when the system umask is set to some values, such as 0077.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 testcases/kernel/syscalls/chdir/chdir01.c | 3 +++
 1 file changed, 3 insertions(+)

--
2.17.1

Comments

Petr Vorel March 30, 2021, 1:04 p.m. UTC | #1
Hi,

NOTE, there was already another solution posted before [1].

I slightly prefer this one as it reverts back previous setup, which is a good
habit, but no hard feeling because it's probably not needed in this case.

I wonder what I'm missing, because although I set system umask 222 (in
/etc/pam.d/common-session and verified it's working) I was not able to trigger
any problem.

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/project/ltp/patch/20210317072652.26974-1-zhaogongyi@huawei.com/
Petr Vorel March 30, 2021, 4:55 p.m. UTC | #2
Hi Ziyao,

thanks, merged!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c
index 60165a6cb..23cd455d6 100644
--- a/testcases/kernel/syscalls/chdir/chdir01.c
+++ b/testcases/kernel/syscalls/chdir/chdir01.c
@@ -55,8 +55,11 @@  static void setup(void)
 	sprintf(workdir, "%s/%s", cwd, MNTPOINT);
 	free(cwd);
 	SAFE_CHDIR(workdir);
+
+	mode_t sys_umask = umask(0);
 	SAFE_MKDIR(DIR_NAME, 0755);
 	SAFE_MKDIR(BLOCKED_NAME, 0644);
+	umask(sys_umask);

 	/* FAT and NTFS override file and directory permissions */
 	SAFE_STAT(BLOCKED_NAME, &statbuf);