[PATCH v1 3/4] tests: improve quotactl coverage
Dmitry V. Levin
ldv at altlinux.org
Tue Jul 10 11:48:26 UTC 2018
On Mon, Jul 09, 2018 at 12:11:31AM +0800, Zhibin Li wrote:
> Use check_quota function for invalid commands instead of manually syscall invocation.
instead of manual quotactl syscall invocations.
> In this way injection can also be checked for these commands in the next commit.
>
> * tests/quotactl.c: (print_dqfmt): New function.
* tests/quotactl.c (print_dqfmt): New function.
> (invalid_cmd_str, invalid_id_str): New variables.
(main): Add invalid_cmd_str and invalid_id_str local variables,
remove unused variable rc, use check_quota and print_dqfmt instead of
manual quotactl syscall invocations.
> * tests/quotactl-xfs.c: Removed unused variable rc.
> (invalid_cmd): New variable.
* tests/quotactl-xfs.c (main): : Add invalid_cmd variable, remove unused
variable rc, use check_quota instead of manual quotactl syscall
invocations.
> ---
> tests/quotactl-xfs.c | 35 +++++++++++++++---------
> tests/quotactl.c | 76 +++++++++++++++++++++++++++++++++++++++-------------
> 2 files changed, 80 insertions(+), 31 deletions(-)
>
> diff --git a/tests/quotactl-xfs.c b/tests/quotactl-xfs.c
> index 036b61d2..c08b1584 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[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, sizeof(invalid_cmd),
> + "QCMD(Q_XQUOTAON, %#x /* ???QUOTA */)",
> + QCMD_TYPE(QCMD(Q_XQUOTAON, 0xfacefeed)));
> + check_quota(CQF_ID_SKIP,
> + QCMD(Q_XQUOTAON, 0xfacefeed), invalid_cmd,
> + bogus_dev, bogus_dev_str, bogus_addr);
>
>
> /* Q_XQUOTAOFF */
> @@ -264,11 +264,11 @@ main(void)
> /* Q_XGETQUOTA */
>
> /* Trying our best to get successful result */
> - check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETQUOTA, USRQUOTA)),
> + check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_XGETQUOTA, USRQUOTA)),
> ARG_STR("/dev/sda1"), getuid(), xdq, print_xdisk_quota,
> (intptr_t) 1);
This change is quite different from the description.
If it's a fix (I bet it is), it should rather go to a separate commit.
> - check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETQUOTA, GRPQUOTA)),
> + check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_XGETQUOTA, GRPQUOTA)),
> ARG_STR(NULL), -1, xdq, print_xdisk_quota, (intptr_t) 2);
Likewise.
> @@ -298,21 +298,30 @@ main(void)
> ARG_STR("/dev/sda1"), xqstat, print_xquota_stat, (intptr_t) 1);
>
> check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
> - ARG_STR(QCMD(Q_XGETQSTATV, PRJQUOTA)),
> + ARG_STR(QCMD(Q_XGETQSTAT, USRQUOTA)),
> + ARG_STR("NULL"), xqstat, print_xquota_stat, (intptr_t) 2);
Likewise.
> + check_quota(CQF_ID_SKIP,
> + ARG_STR(QCMD(Q_XGETQSTAT, PRJQUOTA)),
> unterminated, unterminated_str,
> - xqstat + 1, print_xquota_stat, (intptr_t) 2);
> + xqstat + 1);
>
>
> /* Q_XGETQSTATV */
>
> check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
> - ARG_STR(QCMD(Q_XGETQSTAT, USRQUOTA)),
> - ARG_STR("/dev/sda1"), xqstatv, print_xquota_statv, 1);
> + ARG_STR(QCMD(Q_XGETQSTATV, USRQUOTA)),
> + ARG_STR("/dev/sda1"), xqstatv, print_xquota_statv, (intptr_t) 1);
Likewise.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180710/3fb57d06/attachment.bin>
More information about the Strace-devel
mailing list