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

Attachment: pgppo6YISWQ_V.pgp
Description: PGP signature

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to