[PATCH v2 5/7] tests: use check_quota for invalid quotactl commands

Zhibin Li 08826794brmt at gmail.com
Thu Jul 12 09:32:12 UTC 2018


Use check_quota function for invalid commands instead of manual quotactl
syscall invocations. In this way successful injection can also be checked
for these commands in the next commit.

* tests/quotactl.c (main): Add invalid_cmd_str and invalid_id_str local
variables, remove unused variable rc, use check_quota instead of manual
quotactl syscall invocations.
* tests/quotaclt.c (main): Add invalid_cmd_str variable, remove unused
variable rc, use check_quota instead of manual quotactl syscall invocations.
---
 tests/quotactl-xfs.c | 14 +++++++-------
 tests/quotactl.c     | 37 ++++++++++++++++++++-----------------
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/tests/quotactl-xfs.c b/tests/quotactl-xfs.c
index 9955292b..30d20c1b 100644
--- a/tests/quotactl-xfs.c
+++ b/tests/quotactl-xfs.c
@@ -207,7 +207,7 @@ main(void)
 	char bogus_addr_str[sizeof(void *) * 2 + sizeof("0x")];
 	char unterminated_str[sizeof(void *) * 2 + sizeof("0x")];
 
-	long rc;
+	static char invalid_cmd_str[1024];
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct fs_disk_quota, xdq);
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct fs_quota_stat, xqstat);
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct fs_quota_statv, xqstatv);
@@ -234,12 +234,12 @@ main(void)
 		    "|XFS_QUOTA_GDQ_ACCT|XFS_QUOTA_GDQ_ENFD"
 		    "|XFS_QUOTA_PDQ_ENFD|0xdeadbec0]");
 
-	rc = syscall(__NR_quotactl, QCMD(Q_XQUOTAON, 0xfacefeed), bogus_dev,
-		     bogus_id, bogus_addr);
-	printf("quotactl(QCMD(Q_XQUOTAON, %#x /* ???QUOTA */)"
-	       ", %s, %p) = %s\n",
-	       QCMD_TYPE(QCMD(Q_XQUOTAON, 0xfacefeed)),
-	       bogus_dev_str, bogus_addr, sprintrc(rc));
+	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
+		 "QCMD(Q_XQUOTAON, %#x /* ???QUOTA */)",
+		 QCMD_TYPE(QCMD(Q_XQUOTAON, 0xfacefeed)));
+	check_quota(CQF_ID_SKIP,
+		    QCMD(Q_XQUOTAON, 0xfacefeed), invalid_cmd_str,
+		    bogus_dev, bogus_dev_str, bogus_addr);
 
 
 	/* Q_XQUOTAOFF */
diff --git a/tests/quotactl.c b/tests/quotactl.c
index 21d20102..90156a17 100644
--- a/tests/quotactl.c
+++ b/tests/quotactl.c
@@ -193,6 +193,7 @@ print_dqfmt(long rc, void *ptr, void *arg)
 	printf("%s]", fmtstr);
 }
 
+
 int
 main(void)
 {
@@ -202,7 +203,8 @@ main(void)
 	char bogus_special_str[sizeof(void *) * 2 + sizeof("0x")];
 	char unterminated_str[sizeof(void *) * 2 + sizeof("0x")];
 
-	long rc;
+	static char invalid_cmd_str[1024];
+	static char invalid_id_str[1024];
 	char *unterminated = tail_memdup(unterminated_data,
 					 sizeof(unterminated_data));
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct if_dqblk, dqblk);
@@ -210,7 +212,6 @@ main(void)
 	TAIL_ALLOC_OBJECT_CONST_PTR(uint32_t, fmt);
 	TAIL_ALLOC_OBJECT_CONST_PTR(struct if_nextdqblk, nextdqblk);
 
-
 	snprintf(bogus_special_str, sizeof(bogus_special_str), "%p",
 		bogus_special);
 	snprintf(unterminated_str, sizeof(unterminated_str), "%p",
@@ -219,16 +220,16 @@ main(void)
 
 	/* Invalid commands */
 
-	rc = syscall(__NR_quotactl, bogus_cmd, bogus_special, bogus_id,
-		     bogus_addr);
-	printf("quotactl(QCMD(%#x /* Q_??? */, %#x /* ???QUOTA */)"
-	       ", %p, %u, %p) = %s\n",
-	       QCMD_CMD(bogus_cmd), QCMD_TYPE(bogus_cmd),
-	       bogus_special, bogus_id, bogus_addr, sprintrc(rc));
+	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
+		 "QCMD(%#x /* Q_??? */, %#x /* ???QUOTA */)",
+		 QCMD_CMD(bogus_cmd), QCMD_TYPE(bogus_cmd));
+	check_quota(CQF_NONE, bogus_cmd, invalid_cmd_str,
+		    bogus_special, bogus_special_str, bogus_id, bogus_addr);
 
-	rc = syscall(__NR_quotactl, 0, NULL, -1, NULL);
-	printf("quotactl(QCMD(0 /* Q_??? */, USRQUOTA), NULL, -1, NULL) = %s\n",
-	       sprintrc(rc));
+	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
+		 "QCMD(0 /* Q_??? */, USRQUOTA)");
+	check_quota(CQF_ADDR_STR, 0, invalid_cmd_str,
+		    ARG_STR(NULL), -1, ARG_STR(NULL));
 
 
 	/* Q_QUOTAON */
@@ -238,12 +239,14 @@ main(void)
 		    ARG_STR("/dev/bogus/"), ARG_STR(QFMT_VFS_OLD),
 		    ARG_STR("/tmp/bogus/"));
 
-	rc = syscall(__NR_quotactl, QCMD(Q_QUOTAON, 0xfacefeed), bogus_dev,
-		     bogus_id, bogus_addr);
-	printf("quotactl(QCMD(Q_QUOTAON, %#x /* ???QUOTA */)"
-	       ", %s, %#x /* QFMT_VFS_??? */, %p) = %s\n",
-	       QCMD_TYPE(QCMD(Q_QUOTAON, 0xfacefeed)),
-	       bogus_dev_str, bogus_id, bogus_addr, sprintrc(rc));
+	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
+		 "QCMD(Q_QUOTAON, %#x /* ???QUOTA */)",
+		 QCMD_TYPE(QCMD(Q_QUOTAON, 0xfacefeed)));
+	snprintf(invalid_id_str, sizeof(invalid_id_str),
+		 "%#x /* QFMT_VFS_??? */", bogus_id);
+	check_quota(CQF_ID_STR, QCMD(Q_QUOTAON, 0xfacefeed),
+		    invalid_cmd_str, bogus_dev, bogus_dev_str,
+		    bogus_id, invalid_id_str, bogus_addr);
 
 
 	/* Q_QUOTAOFF */
-- 
2.14.4



More information about the Strace-devel mailing list