This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 4/5] tst-chk1: add fd_set dynamic allocation test
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>
- Cc: libc-alpha at sourceware dot org, libc-ports at sourceware dot org
- Date: Tue, 30 Apr 2013 22:44:02 -0400
- Subject: Re: [PATCH 4/5] tst-chk1: add fd_set dynamic allocation test
- References: <1365900451-19026-1-git-send-email-kosaki dot motohiro at gmail dot com> <1365900451-19026-5-git-send-email-kosaki dot motohiro at gmail dot com>
On 04/13/2013 08:47 PM, KOSAKI Motohiro wrote:
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
> ---
> ChangeLog | 5 ++++
> debug/tst-chk1.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 67 insertions(+), 1 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index 7cdece7..b154c3c 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -29,6 +29,11 @@
>
> 2013-03-25 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
>
> + * debug/tst-chk1.c (do_test): Added tests for fd_set allocation
> + from heap.
> +
> +2013-03-25 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
> +
> * debug/fdelt_chk.c (__fdelt_chk): Removed range check
> and renamed to __fdelt_nochk.
>
> diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
> index 6ca8d9d..2b225ad 100644
> --- a/debug/tst-chk1.c
> +++ b/debug/tst-chk1.c
> @@ -32,7 +32,7 @@
> #include <sys/select.h>
> #include <sys/socket.h>
> #include <sys/un.h>
> -
> +#include <sys/param.h>
>
> #define obstack_chunk_alloc malloc
> #define obstack_chunk_free free
> @@ -1451,24 +1451,85 @@ do_test (void)
> #endif
>
> fd_set s;
> + fd_set *pfdset;
> FD_ZERO (&s);
> FD_SET (FD_SETSIZE - 1, &s);
> #if __USE_FORTIFY_LEVEL >= 1
> CHK_FAIL_START
> FD_SET (FD_SETSIZE, &s);
> CHK_FAIL_END
Please add comments explaining *why* we are testing this usage
pattern e.g. Linux and BSDs support fds > FD_SETSIZE.
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE+1, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + FD_SET (FD_SETSIZE, pfdset);
> + free (pfdset);
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE*2, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + CHK_FAIL_START
> + FD_SET (FD_SETSIZE*2, pfdset);
> + CHK_FAIL_END
> + free (pfdset);
> #endif
> FD_CLR (FD_SETSIZE - 1, &s);
> #if __USE_FORTIFY_LEVEL >= 1
> CHK_FAIL_START
> FD_CLR (FD_SETSIZE, &s);
> CHK_FAIL_END
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE+1, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + FD_CLR (FD_SETSIZE, pfdset);
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE*2, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + free (pfdset);
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE*2, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + CHK_FAIL_START
> + FD_CLR (FD_SETSIZE*2, pfdset);
> + CHK_FAIL_END
> + free (pfdset);
> #endif
> FD_ISSET (FD_SETSIZE - 1, &s);
> #if __USE_FORTIFY_LEVEL >= 1
> CHK_FAIL_START
> FD_ISSET (FD_SETSIZE, &s);
> CHK_FAIL_END
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE+1, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + FD_ISSET (FD_SETSIZE, pfdset);
> + free (pfdset);
> +
> + pfdset = (fd_set*)calloc(howmany(FD_SETSIZE*2, NFDBITS), sizeof(fd_mask));
> + if (pfdset == NULL) {
> + printf("malloc failed %m\n");
> + return 1;
> + }
> + CHK_FAIL_START
> + FD_ISSET (FD_SETSIZE*2, pfdset);
> + CHK_FAIL_END
> + free (pfdset);
> #endif
>
> struct pollfd fds[1];
>