]> granicus.if.org Git - strace/commitdiff
tests: use check_quota for invalid quotactl commands
authorZhibin Li <08826794brmt@gmail.com>
Thu, 12 Jul 2018 09:32:12 +0000 (17:32 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 15 Jul 2018 18:51:09 +0000 (18:51 +0000)
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
tests/quotactl.c

index 9955292b78130929902bfbbed1fdf8260994b043..30d20c1be82dfaeec282e1fc6fa4c890d222e206 100644 (file)
@@ -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 */
index 21d20102a6a408a31296656503e70afd96f5f9a4..90156a17ddde38297be22e7d63f7b77ff0db6d62 100644 (file)
@@ -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 */