Skip to contentSkip to conversation

Add more testcases in mkdir03

PATCH In review Andrea Cervesato 3 participants 3 messages Feb 22, 2024 – Mar 8, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Add more testcases in mkdir03

From: Andrea Cervesato <[email protected]>

We add more test cases in mkdir03 in order to check that mkdir() can't overwrite certain types of files, such as simlinks, directories, pipes, devices, etc.
These test cases come from symlink01 refactoring.

---
EEXIST test on /dev/null

 runtest/syscalls                          |  1 -
 testcases/kernel/syscalls/mkdir/mkdir03.c | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
runtest/syscalls +0 -1
index ef90076e4..e913eeecd 100644
@@ -757,7 +757,6 @@ mkdir02 mkdir02
 mkdir03 mkdir03
 mkdir04 mkdir04
 mkdir05 mkdir05
-mkdir05A symlink01 -T mkdir05
 mkdir09 mkdir09
 
 #mkdirat test cases
testcases/kernel/syscalls/mkdir/mkdir03.c +16 -0
index d5141bb64..736c91ae2 100644
@@ -9,6 +9,8 @@
  *	EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, ELOOP and EROFS
  */
 
+#include <paths.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -19,6 +21,10 @@
 #include "tst_test.h"
 
 #define TST_EEXIST	"tst_eexist"
+#define TST_PIPE	"tst_pipe"
+#define TST_FOLDER	"tst_folder"
+#define TST_SYMLINK "tst_symlink"
+#define TST_NULLDEV	_PATH_DEVNULL
 #define TST_ENOENT	"tst_enoent/tst"
 #define TST_ENOTDIR_FILE "tst_enotdir"
 #define TST_ENOTDIR_DIR	"tst_enotdir/tst"
@@ -41,6 +47,10 @@ static struct tcase {
 	{NULL, EFAULT},
 	{long_dir, ENAMETOOLONG},
 	{TST_EEXIST, EEXIST},
+	{TST_FOLDER, EEXIST},
+	{TST_PIPE, EEXIST},
+	{TST_SYMLINK, EEXIST},
+	{TST_NULLDEV, EEXIST},
 	{TST_ENOENT, ENOENT},
 	{TST_ENOTDIR_DIR, ENOTDIR},
 	{loop_dir, ELOOP},
@@ -70,7 +80,13 @@ static void verify_mkdir(unsigned int n)
 static void setup(void)
 {
 	unsigned int i;
+	char *tmpdir = tst_get_tmpdir();
 
+	SAFE_SYMLINK(tmpdir, TST_SYMLINK);
+	free(tmpdir);
+
+	SAFE_MKFIFO(TST_PIPE, 0777);
+	SAFE_MKDIR(TST_FOLDER, 0777);
 	SAFE_TOUCH(TST_EEXIST, MODE, NULL);
 	SAFE_TOUCH(TST_ENOTDIR_FILE, MODE, NULL);
 
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 1/1
#1 lore raw

Hi!

testcases/kernel/syscalls/mkdir/mkdir03.c line 27

Quoted 13 lines
testcases/kernel/syscalls/mkdir/mkdir03.c +6 -0
+#include <paths.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -19,6 +21,10 @@
 #include "tst_test.h"
 
 #define TST_EEXIST	"tst_eexist"
+#define TST_PIPE	"tst_pipe"
+#define TST_FOLDER	"tst_folder"
+#define TST_SYMLINK "tst_symlink"
+#define TST_NULLDEV	_PATH_DEVNULL

I would just hardcode the "/dev/null" here, this has potential to explode on alternative libc implementations, possibly Android.

Hmm looking around the file seems to exists on Android and Musl however _PATH_DEVNULL is just "/dev/null" everywhere anyways.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 18 lines

Hi!

testcases/kernel/syscalls/mkdir/mkdir03.c line 27

Quoted 13 lines
testcases/kernel/syscalls/mkdir/mkdir03.c +6 -0
+#include <paths.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -19,6 +21,10 @@
 #include "tst_test.h"
 
 #define TST_EEXIST	"tst_eexist"
+#define TST_PIPE	"tst_pipe"
+#define TST_FOLDER	"tst_folder"
+#define TST_SYMLINK "tst_symlink"
+#define TST_NULLDEV	_PATH_DEVNULL

I would just hardcode the "/dev/null" here, this has potential to explode on alternative libc implementations, possibly Android.

Quoted 2 lines

Hmm looking around the file seems to exists on Android and Musl however _PATH_DEVNULL is just "/dev/null" everywhere anyways.

Yeah, IMHO not that readable as hardcoded value, but it's safe to use nowadays.

Anyway, merged.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp