[PATCH v2 1/4] tests: add xetrlimit.test
Dmitry V. Levin
ldv at altlinux.org
Fri Mar 11 01:54:07 UTC 2016
On Thu, Mar 10, 2016 at 05:12:22PM +0800, Fei Jie wrote:
[...]
> --- /dev/null
> +++ b/tests/xetrlimit.c
> @@ -0,0 +1,36 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#if defined __NR_getrlimit && defined __NR_setrlimit
> +
> +# include <errno.h>
> +# include <sys/time.h>
> +# include <sys/resource.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +
> +int
> +main(void)
> +{
> + struct rlimit *const rlim = tail_alloc(sizeof(struct rlimit));
> + int rc = syscall(__NR_getrlimit, RLIMIT_RTPRIO, rlim);
> +
> + printf("getrlimit(RLIMIT_RTPRIO, {rlim_cur=%d, rlim_max=%d}) = %d\n",
> + (int) rlim->rlim_cur, (int) rlim->rlim_max, rc);
Sorry but these casts of struct rlimit members to int defeat the main
purpose of a getrlimit/setrlimit as I understand it, which is to check
that struct rlimit is decoded properly.
> + rlim->rlim_cur = rlim->rlim_max + 1;
> + rc = syscall(__NR_setrlimit, RLIMIT_RTPRIO, rlim);
> + printf("setrlimit(RLIMIT_RTPRIO, {rlim_cur=%d, rlim_max=%d})"
> + " = %d %s (%m)\n",
> + (int) rlim->rlim_cur, (int) rlim->rlim_max, rc,
> + errno == EPERM ? "EPERM" : "EINVAL");
If I were writing this test, I'd store sufficiently large 64-bit values
into struct rlimit and at the same time made sure that rlim_cur > rlim_max
both in 32-bit and 64-bit representations, thus forcing setrlimit to fail
with EINVAL.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160311/e105673f/attachment.bin>
More information about the Strace-devel
mailing list