bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* *printf-posix: Avoid crash in a configure test
@ 2024-02-20 11:07 Bruno Haible
  2024-02-21 11:51 ` Bruno Haible
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2024-02-20 11:07 UTC (permalink / raw)
  To: bug-gnulib

After configuring my dev environment to leave core dumps in /var/crash,
I see that a 'configure' run in a testdir of all of gnulib produces one
core dump, and I get a UI notification of it. The cause is the test program
that tests whether *printf supports the %n directive: it triggers an abort(),
which produces a core dump:

  $ gcc -O2 -g conftest.c && ./a.out 
  *** %n in writable segment detected ***
  Aborted (core dumped)


This patch fixes it.


2024-02-20  Bruno Haible  <bruno@clisp.org>

	*printf-posix: Avoid crash in a configure test.
	* m4/printf.m4 (gl_PRINTF_DIRECTIVE_N): In the test program, catch the
	SIGABRT signal, so that the program does not dump core.

diff --git a/m4/printf.m4 b/m4/printf.m4
index bb67d59409..05bf7fe1df 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 89
+# printf.m4 serial 90
 dnl Copyright (C) 2003, 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -890,6 +890,7 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N]
     [
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -907,6 +908,12 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N]
   exit (1);
 }
 #endif
+static void
+abort_handler (int sig)
+{
+  (void) sig;
+  _exit (1);
+}
 static char fmtstring[10];
 static char buf[100];
 int main ()
@@ -915,6 +922,7 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_N]
 #ifdef _MSC_VER
   _set_invalid_parameter_handler (invalid_parameter_handler);
 #endif
+  signal (SIGABRT, abort_handler);
   /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
      support %n in format strings in read-only memory but not in writable
      memory.  */





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

* Re: *printf-posix: Avoid crash in a configure test
  2024-02-20 11:07 *printf-posix: Avoid crash in a configure test Bruno Haible
@ 2024-02-21 11:51 ` Bruno Haible
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2024-02-21 11:51 UTC (permalink / raw)
  To: bug-gnulib

> 2024-02-20  Bruno Haible  <bruno@clisp.org>
> 
> 	*printf-posix: Avoid crash in a configure test.
> 	* m4/printf.m4 (gl_PRINTF_DIRECTIVE_N): In the test program, catch the
> 	SIGABRT signal, so that the program does not dump core.

There's another configure test that also exercises %n.


2024-02-21  Bruno Haible  <bruno@clisp.org>

	*printf-posix: Avoid crash in another configure test.
	* m4/printf.m4 (gl_SNPRINTF_DIRECTIVE_N): In the test program, catch the
	SIGABRT signal, so that the program does not dump core.

diff --git a/m4/printf.m4 b/m4/printf.m4
index 05bf7fe1df..6f917778e8 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1705,6 +1705,7 @@ AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N]
     [
       AC_RUN_IFELSE(
         [AC_LANG_SOURCE([[
+#include <signal.h>
 #include <stdio.h>
 #include <string.h>
 #if HAVE_SNPRINTF
@@ -1721,11 +1722,18 @@ AC_DEFUN([gl_SNPRINTF_DIRECTIVE_N]
   return ret;
 }
 #endif
+static void
+abort_handler (int sig)
+{
+  (void) sig;
+  _exit (1);
+}
 static char fmtstring[10];
 static char buf[100];
 int main ()
 {
   int count = -1;
+  signal (SIGABRT, abort_handler);
   /* Copy the format string.  Some systems (glibc with _FORTIFY_SOURCE=2)
      support %n in format strings in read-only memory but not in writable
      memory.  */





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

end of thread, other threads:[~2024-02-21 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-20 11:07 *printf-posix: Avoid crash in a configure test Bruno Haible
2024-02-21 11:51 ` Bruno Haible

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).