[PATCH v2 6/6] tests: add a test case for the abitrator of ioctl command overwrapping

Masatake YAMATO yamato at redhat.com
Fri Mar 11 18:02:09 UTC 2022


* tests/ioctl_overwrap.c: New test case.
* tests/.gitignore: Add the ioctl_overwrap test case.
* tests/gen_tests.in: add an entry for ioctl_overwrap.
* tests/pure_executables.list: add ioctl_overwrap command.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 tests/.gitignore            |  1 +
 tests/gen_tests.in          |  1 +
 tests/ioctl_overwrap.c      | 71 +++++++++++++++++++++++++++++++++++++
 tests/pure_executables.list |  1 +
 4 files changed, 74 insertions(+)
 create mode 100644 tests/ioctl_overwrap.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 6c212c38a..130d2432d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -334,6 +334,7 @@ ioctl_mtd
 ioctl_mtd-success
 ioctl_nbd
 ioctl_nsfs
+ioctl_overwrap
 ioctl_perf
 ioctl_perf-success
 ioctl_ptp
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index b98a733a0..79d4796c7 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -348,6 +348,7 @@ ioctl_mtd	+ioctl.test
 ioctl_mtd-success	+ioctl-success.sh -a26
 ioctl_nbd	+ioctl.test -y
 ioctl_nsfs	+ioctl.test -esignal=none
+ioctl_overwrap	+ioctl.test
 ioctl_perf	+ioctl.test
 ioctl_perf-success +ioctl-success.sh -a35
 ioctl_ptp	+ioctl.test
diff --git a/tests/ioctl_overwrap.c b/tests/ioctl_overwrap.c
new file mode 100644
index 000000000..bfbaddba4
--- /dev/null
+++ b/tests/ioctl_overwrap.c
@@ -0,0 +1,71 @@
+/*
+ * Test the code arbitrating the overwrapped IOCTL commands
+ *
+ * Copyright (c) 2022 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <asm/ioctls.h>
+#include <linux/soundcard.h>
+#include <linux/limits.h>
+
+int
+main(int argc, char **argv)
+{
+	skip_if_unavailable("/proc/self/fd/");
+
+#if SNDCTL_TMR_START == TCSETS
+	struct termios tos;
+	memset(&tos, 0, sizeof(tos));
+
+	int ptm = posix_openpt(O_RDWR);
+	if (ptm < 0)
+		perror_msg_and_skip("posix_openpt(O_RDWR)");
+
+	int unlock = 0;
+	if (ioctl(ptm, TIOCSPTLCK, &unlock) < 0)
+		perror_msg_and_skip("ioctl(%d, TIOCSPTLCK, ...)", ptm);
+	printf("ioctl(%d, TIOCSPTLCK, [0]) = 0\n", ptm);
+
+	int slvnum;
+	if (ioctl(ptm, TIOCGPTN, &slvnum) < 0)
+		error_msg_and_skip("ioctl(%d, TIOCGPTN, ...)", ptm);
+	printf("ioctl(%d, TIOCGPTN, [%d]) = 0\n", ptm, slvnum);
+
+	char slvdev[PATH_MAX];
+	snprintf(slvdev, sizeof(slvdev), "/dev/pts/%d", slvnum);
+
+	int pts = open(slvdev, O_RDWR);
+	if (pts < 0)
+		perror_msg_and_fail("open(%s)", slvdev);
+
+	if (ioctl(pts, TCSETS, &tos) < 0)
+		perror_msg_and_fail("ioctl(%d, TCSETS, ...)", pts);
+	printf("ioctl(%d, TCSETS, {B0 -opost -isig -icanon -echo ...}) = 0\n", pts);
+
+	int devnull = open("/dev/null", O_RDWR);
+	if (pts < 0)
+		perror_msg_and_fail("open(/dev/null)");
+
+	ioctl(devnull, TCSETS, &tos);
+	printf("ioctl(%d, SNDCTL_TMR_START or TCSETS, {B0 -opost -isig -icanon -echo ...}) = %s\n",
+	       devnull, sprintrc(-1));
+
+	puts("+++ exited with 0 +++");
+	return 0;
+#else
+	error_msg_and_skip("SNDCTL_TMR_START is not equals to TCSETS", ptm);
+#endif
+}
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index fe02fabb7..f11cfd3ce 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -220,6 +220,7 @@ ioctl_kvm_run_auxstr_vcpu
 ioctl_loop
 ioctl_mtd
 ioctl_nbd
+ioctl_overwrap
 ioctl_perf
 ioctl_ptp
 ioctl_random
-- 
2.35.1



More information about the Strace-devel mailing list