public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] debug: Actually run tst-longjmp_chk3.c
@ 2023-06-01 21:20 Nisha Poyarekar
  2023-06-05 19:55 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 2+ messages in thread
From: Nisha Poyarekar @ 2023-06-01 21:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Nisha Poyarekar

tst-longjmp_c.c test was not run at all because there was no
entry for it in the Makefile. With this change, I have also
included the new test-driver.c instead of test-skeleton.c.

Signed-off-by: Nisha Poyarekar <nisha.s.menon@gmail.com>
---
 debug/Makefile           |  1 +
 debug/tst-longjmp_chk3.c | 30 +++++++++++++-----------------
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/debug/Makefile b/debug/Makefile
index 096df27aeb..e19aa1107a 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -279,6 +279,7 @@ tests = \
   tst-backtrace6 \
   tst-longjmp_chk \
   tst-longjmp_chk2 \
+  tst-longjmp_chk3 \
   tst-realpath-chk \
   tst-sprintf-fortify-unchecked \
   # tests
diff --git a/debug/tst-longjmp_chk3.c b/debug/tst-longjmp_chk3.c
index f1e576ad5b..ea0e67d2a6 100644
--- a/debug/tst-longjmp_chk3.c
+++ b/debug/tst-longjmp_chk3.c
@@ -18,13 +18,12 @@
 
 #include <setjmp.h>
 #include <signal.h>
+#include <stdio.h>
 #include <string.h>
 
-static int do_test (void);
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/check.h>
+#include <support/support.h>
 
-static char buf[SIGSTKSZ * 4];
 static jmp_buf jb;
 
 static void
@@ -49,18 +48,17 @@ static int
 do_test (void)
 {
   stack_t ss;
+  size_t bufsize = SIGSTKSZ * 4;
+  void *buf = xmalloc (bufsize);
 
   set_fortify_handler (handler);
 
   /* Create a valid signal stack and enable it.  */
   ss.ss_sp = buf;
-  ss.ss_size = sizeof (buf);
+  ss.ss_size = bufsize;
   ss.ss_flags = 0;
   if (sigaltstack (&ss, NULL) < 0)
-    {
-      printf ("first sigaltstack failed: %m\n");
-      return 1;
-    }
+    FAIL_RET ("first sigaltstack failed: %m\n");
 
   /* Trigger the signal handler which will create a jmpbuf that points to the
      end of the signal stack.  */
@@ -69,17 +67,15 @@ do_test (void)
 
   /* Shrink the signal stack so the jmpbuf is now invalid.
      We adjust the start & end to handle stacks that grow up & down.  */
-  ss.ss_sp = buf + sizeof (buf) / 2;
-  ss.ss_size = sizeof (buf) / 4;
+  ss.ss_sp = buf + bufsize / 2;
+  ss.ss_size = bufsize / 4;
   if (sigaltstack (&ss, NULL) < 0)
-    {
-      printf ("second sigaltstack failed: %m\n");
-      return 1;
-    }
+    FAIL_RET ("second sigaltstack failed: %m\n");
 
   /* This should fail.  */
   longjmp (jb, 1);
 
-  puts ("longjmp returned and shouldn't");
-  return 1;
+  FAIL_RET ("longjmp returned and shouldn't");
 }
+
+#include <support/test-driver.c>
-- 
2.37.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] debug: Actually run tst-longjmp_chk3.c
  2023-06-01 21:20 [PATCH] debug: Actually run tst-longjmp_chk3.c Nisha Poyarekar
@ 2023-06-05 19:55 ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2023-06-05 19:55 UTC (permalink / raw)
  To: Nisha Poyarekar, libc-alpha



On 01/06/23 18:20, Nisha Poyarekar via Libc-alpha wrote:
> tst-longjmp_c.c test was not run at all because there was no
> entry for it in the Makefile. With this change, I have also
> included the new test-driver.c instead of test-skeleton.c.
> 
> Signed-off-by: Nisha Poyarekar <nisha.s.menon@gmail.com>

Maybe use libsupport xalloc_sigstack? Something like:

static int
do_test (void)
{
  set_fortify_handler (handler);

  /* Create a valid signal stack and enable it.  */
  sstk1 = xalloc_sigstack (SIGSTKSZ * 4);

  /* Trigger the signal handler which will create a jmpbuf that points to the
     end of the signal stack.  */
  signal (SIGUSR1, handler);
  kill (getpid (), SIGUSR1);

  /* Shrink the signal stack so the jmpbuf is now invalid.  */
  sstk2 = xalloc_sigstack (SIGSTKSZ);

  /* This should fail.  */
  longjmp (jb, 1);

  FAIL_RET ("longjmp returned and shouldn't");
}

And xfree_sigstack before exit.


> ---
>  debug/Makefile           |  1 +
>  debug/tst-longjmp_chk3.c | 30 +++++++++++++-----------------
>  2 files changed, 14 insertions(+), 17 deletions(-)
> 
> diff --git a/debug/Makefile b/debug/Makefile
> index 096df27aeb..e19aa1107a 100644
> --- a/debug/Makefile
> +++ b/debug/Makefile
> @@ -279,6 +279,7 @@ tests = \
>    tst-backtrace6 \
>    tst-longjmp_chk \
>    tst-longjmp_chk2 \
> +  tst-longjmp_chk3 \
>    tst-realpath-chk \
>    tst-sprintf-fortify-unchecked \
>    # tests
> diff --git a/debug/tst-longjmp_chk3.c b/debug/tst-longjmp_chk3.c
> index f1e576ad5b..ea0e67d2a6 100644
> --- a/debug/tst-longjmp_chk3.c
> +++ b/debug/tst-longjmp_chk3.c
> @@ -18,13 +18,12 @@
>  
>  #include <setjmp.h>
>  #include <signal.h>
> +#include <stdio.h>
>  #include <string.h>
>  
> -static int do_test (void);
> -#define TEST_FUNCTION do_test ()
> -#include "../test-skeleton.c"
> +#include <support/check.h>
> +#include <support/support.h>
>  
> -static char buf[SIGSTKSZ * 4];
>  static jmp_buf jb;
>  
>  static void
> @@ -49,18 +48,17 @@ static int
>  do_test (void)
>  {
>    stack_t ss;
> +  size_t bufsize = SIGSTKSZ * 4;
> +  void *buf = xmalloc (bufsize);
>  
>    set_fortify_handler (handler);
>  
>    /* Create a valid signal stack and enable it.  */
>    ss.ss_sp = buf;
> -  ss.ss_size = sizeof (buf);
> +  ss.ss_size = bufsize;
>    ss.ss_flags = 0;
>    if (sigaltstack (&ss, NULL) < 0)
> -    {
> -      printf ("first sigaltstack failed: %m\n");
> -      return 1;
> -    }
> +    FAIL_RET ("first sigaltstack failed: %m\n");
>  
>    /* Trigger the signal handler which will create a jmpbuf that points to the
>       end of the signal stack.  */
> @@ -69,17 +67,15 @@ do_test (void)
>  
>    /* Shrink the signal stack so the jmpbuf is now invalid.
>       We adjust the start & end to handle stacks that grow up & down.  */
> -  ss.ss_sp = buf + sizeof (buf) / 2;
> -  ss.ss_size = sizeof (buf) / 4;
> +  ss.ss_sp = buf + bufsize / 2;
> +  ss.ss_size = bufsize / 4;
>    if (sigaltstack (&ss, NULL) < 0)
> -    {
> -      printf ("second sigaltstack failed: %m\n");
> -      return 1;
> -    }
> +    FAIL_RET ("second sigaltstack failed: %m\n");
>  
>    /* This should fail.  */
>    longjmp (jb, 1);
>  
> -  puts ("longjmp returned and shouldn't");
> -  return 1;
> +  FAIL_RET ("longjmp returned and shouldn't");
>  }
> +
> +#include <support/test-driver.c>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-05 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 21:20 [PATCH] debug: Actually run tst-longjmp_chk3.c Nisha Poyarekar
2023-06-05 19:55 ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).