[LTP] [PATCH 5/6] syscalls/chmod01: Make use of guarded buffers

Cyril Hrubis chrubis@suse.cz
Fri Aug 11 13:56:46 CEST 2023


Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/chmod/chmod01.c | 28 +++++++++++++++--------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/chmod/chmod01.c b/testcases/kernel/syscalls/chmod/chmod01.c
index 9f5ec4c67..b3b828ac3 100644
--- a/testcases/kernel/syscalls/chmod/chmod01.c
+++ b/testcases/kernel/syscalls/chmod/chmod01.c
@@ -19,13 +19,16 @@
 
 static int modes[] = {0, 07, 070, 0700, 0777, 02777, 04777, 06777};
 
+static char *test_dir;
+static char *test_file;
+
 static struct variant {
-	char *name;
+	char **name;
 	unsigned int mode_mask;
 	char *desc;
 } variants[] = {
-	{TESTFILE, S_IFREG, "verify permissions of file"},
-	{TESTDIR, S_IFDIR, "verify permissions of directory"},
+	{&test_file, S_IFREG, "verify permissions of file"},
+	{&test_dir, S_IFDIR, "verify permissions of directory"},
 };
 
 static void verify_chmod(unsigned int n)
@@ -34,21 +37,21 @@ static void verify_chmod(unsigned int n)
 	int mode = modes[n];
 	struct variant *tc = &variants[tst_variant];
 
-	TST_EXP_PASS(chmod(tc->name, mode), "chmod(%s, %04o)",
-	             tc->name, mode);
+	TST_EXP_PASS(chmod(*tc->name, mode), "chmod(%s, %04o)",
+	             *tc->name, mode);
 
 	if (!TST_PASS)
 		return;
 
-	SAFE_STAT(tc->name, &stat_buf);
+	SAFE_STAT(*tc->name, &stat_buf);
 	stat_buf.st_mode &= ~tc->mode_mask;
 
 	if (stat_buf.st_mode == (unsigned int)mode) {
 		tst_res(TPASS, "stat(%s) mode=%04o",
-				tc->name, stat_buf.st_mode);
+				*tc->name, stat_buf.st_mode);
 	} else {
 		tst_res(TFAIL, "stat(%s) mode=%04o",
-				tc->name, stat_buf.st_mode);
+				*tc->name, stat_buf.st_mode);
 	}
 }
 
@@ -57,9 +60,9 @@ static void setup(void)
 	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 
 	if (tst_variant)
-		SAFE_MKDIR(variants[tst_variant].name, MODE);
+		SAFE_MKDIR(*variants[tst_variant].name, MODE);
 	else
-		SAFE_TOUCH(variants[tst_variant].name, MODE, NULL);
+		SAFE_TOUCH(*variants[tst_variant].name, MODE, NULL);
 }
 
 static struct tst_test test = {
@@ -68,4 +71,9 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(modes),
 	.test = verify_chmod,
 	.needs_tmpdir = 1,
+	.bufs = (struct tst_buffers []) {
+		{&test_file, .str = TESTFILE},
+		{&test_dir, .str = TESTDIR},
+		{}
+	}
 };
-- 
2.41.0



More information about the ltp mailing list