bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

raise, signal on MSVC


From: Bruno Haible
Subject: raise, signal on MSVC
Date: Sat, 24 Sep 2011 00:53:24 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Not only bad file descriptors lead to invalid parameter crashes, but also
invalid signal numbers, as arguments to the signal() function.

With signal():
Crashes: 0 5 7 9 10 12 14 18 19 20
Valid: 1 2 3 4 8 11 13 15 16 17 21 22

With raise(): 1 3 13 16 17 also crash.


First, a renewed 'raise' module.


2011-09-23  Bruno Haible  <address@hidden>

        raise: Support for MSVC.
        * lib/signal.in.h (raise): New declaration.
        * lib/raise.c (raise_nothrow, rpl_raise): New alternate implementation
        for native Windows platforms.
        * m4/raise.m4: New file.
        * m4/signal_h.m4 (gl_SIGNAL_H_DEFAULTS): Initialize GNULIB_RAISE,
        HAVE_RAISE, REPLACE_RAISE.
        * modules/signal (Makefile.am): Substitute GNULIB_RAISE, HAVE_RAISE,
        REPLACE_RAISE.
        * modules/raise (Status, Notice): Remove fields.
        (Files): Add m4/raise.m4.
        (Depends-on): Add signal, msvc-inval.
        (configure.ac): Use the common idioms.
        (Maintainer): Add me.
        * tests/test-signal-c++.cc: Check the signature of raise.
        * doc/posix-functions/raise.texi: Mention the problem on MSVC.

================================= m4/raise.m4 =================================
# raise.m4 serial 1
dnl Copyright (C) 2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_RAISE],
[
  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
  AC_REQUIRE([AC_CANONICAL_HOST])
  AC_REQUIRE([gl_MSVC_INVAL])
  AC_CHECK_FUNCS([raise])
  if test $ac_cv_func_raise = no; then
    HAVE_RAISE=0
  else
    if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
      REPLACE_RAISE=1
    fi
  fi
])

# Prerequisites of lib/raise.c.
AC_DEFUN([gl_PREREQ_RAISE], [
  AC_REQUIRE([AC_C_INLINE])
])
===============================================================================
--- doc/posix-functions/raise.texi.orig Sat Sep 24 00:44:09 2011
+++ doc/posix-functions/raise.texi      Sat Sep 24 00:04:46 2011
@@ -10,6 +10,9 @@
 @itemize
 @item
 This function is missing on some old platforms.
address@hidden
+This function crashes when invoked with invalid arguments on some platforms:
+MSVC 9.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- lib/raise.c.orig    Sat Sep 24 00:44:09 2011
+++ lib/raise.c Sat Sep 24 00:13:44 2011
@@ -15,16 +15,59 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* written by Jim Meyering */
+/* written by Jim Meyering and Bruno Haible */
 
 #include <config.h>
 
-#include <sys/types.h>
+/* Specification.  */
 #include <signal.h>
-#include <unistd.h>
+
+#if HAVE_RAISE
+/* Native Windows platform.  */
+
+# include <errno.h>
+
+# include "msvc-inval.h"
+
+# undef raise
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static inline int
+raise_nothrow (int sig)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = raise (sig);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EINVAL;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#  define raise raise_nothrow
+# endif
+
+int
+rpl_raise (int sig)
+{
+  return raise_nothrow (sig);
+}
+
+#else
+/* An old Unix platform.  */
+
+# include <unistd.h>
 
 int
 raise (int sig)
 {
   return kill (getpid (), sig);
 }
+
+#endif
--- lib/signal.in.h.orig        Sat Sep 24 00:44:09 2011
+++ lib/signal.in.h     Sat Sep 24 00:39:02 2011
@@ -152,6 +152,29 @@
 #endif
 
 
+#if @GNULIB_RAISE@
+# if @REPLACE_RAISE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef raise
+#   define raise rpl_raise
+#  endif
+_GL_FUNCDECL_RPL (raise, int, (int sig));
+_GL_CXXALIAS_RPL (raise, int, (int sig));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (raise, int, (int sig));
+#  endif
+_GL_CXXALIAS_SYS (raise, int, (int sig));
+# endif
+_GL_CXXALIASWARN (raise);
+#elif defined GNULIB_POSIXCHECK
+# undef raise
+/* Assume raise is always declared.  */
+_GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
+                 "use gnulib module raise for portability");
+#endif
+
+
 #if @GNULIB_SIGPROCMASK@
 # if address@hidden@
 
--- m4/signal_h.m4.orig Sat Sep 24 00:44:09 2011
+++ m4/signal_h.m4      Sat Sep 24 00:23:02 2011
@@ -1,4 +1,4 @@
-# signal_h.m4 serial 17
+# signal_h.m4 serial 18
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -62,12 +62,14 @@
 AC_DEFUN([gl_SIGNAL_H_DEFAULTS],
 [
   GNULIB_PTHREAD_SIGMASK=0;    AC_SUBST([GNULIB_PTHREAD_SIGMASK])
+  GNULIB_RAISE=0;              AC_SUBST([GNULIB_RAISE])
   GNULIB_SIGNAL_H_SIGPIPE=0;   AC_SUBST([GNULIB_SIGNAL_H_SIGPIPE])
   GNULIB_SIGPROCMASK=0;        AC_SUBST([GNULIB_SIGPROCMASK])
   GNULIB_SIGACTION=0;          AC_SUBST([GNULIB_SIGACTION])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING])
   HAVE_PTHREAD_SIGMASK=1;      AC_SUBST([HAVE_PTHREAD_SIGMASK])
+  HAVE_RAISE=1;                AC_SUBST([HAVE_RAISE])
   HAVE_SIGSET_T=1;             AC_SUBST([HAVE_SIGSET_T])
   HAVE_SIGINFO_T=1;            AC_SUBST([HAVE_SIGINFO_T])
   HAVE_SIGACTION=1;            AC_SUBST([HAVE_SIGACTION])
@@ -77,4 +79,5 @@
                                AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T])
   HAVE_SIGHANDLER_T=1;         AC_SUBST([HAVE_SIGHANDLER_T])
   REPLACE_PTHREAD_SIGMASK=0;   AC_SUBST([REPLACE_PTHREAD_SIGMASK])
+  REPLACE_RAISE=0;             AC_SUBST([REPLACE_RAISE])
 ])
--- modules/raise.orig  Sat Sep 24 00:44:10 2011
+++ modules/raise       Sat Sep 24 00:09:02 2011
@@ -1,19 +1,21 @@
 Description:
 Send a signal to the executing process.
 
-Status:
-obsolete
-
-Notice:
-This module is obsolete.
-
 Files:
 lib/raise.c
+m4/raise.m4
 
 Depends-on:
+signal
+msvc-inval      [test $HAVE_RAISE = 0 || test $REPLACE_RAISE = 1]
 
 configure.ac:
-AC_REPLACE_FUNCS(raise)
+gl_FUNC_RAISE
+if test $HAVE_RAISE = 0 || test $REPLACE_RAISE = 1; then
+  AC_LIBOBJ([raise])
+  gl_PREREQ_RAISE
+fi
+gl_SIGNAL_MODULE_INDICATOR([raise])
 
 Makefile.am:
 
@@ -24,5 +26,5 @@
 LGPLv2+
 
 Maintainer:
-Jim Meyering
+Jim Meyering, Bruno Haible
 
--- modules/signal.orig Sat Sep 24 00:44:10 2011
+++ modules/signal      Sat Sep 24 00:24:35 2011
@@ -29,11 +29,13 @@
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SIGNAL_H''@|$(NEXT_SIGNAL_H)|g' \
              -e 's|@''GNULIB_PTHREAD_SIGMASK''@|$(GNULIB_PTHREAD_SIGMASK)|g' \
+             -e 's|@''GNULIB_RAISE''@|$(GNULIB_RAISE)|g' \
              -e 's/@''GNULIB_SIGNAL_H_SIGPIPE''@/$(GNULIB_SIGNAL_H_SIGPIPE)/g' 
\
              -e 's/@''GNULIB_SIGPROCMASK''@/$(GNULIB_SIGPROCMASK)/g' \
              -e 's/@''GNULIB_SIGACTION''@/$(GNULIB_SIGACTION)/g' \
              -e 
's|@''HAVE_POSIX_SIGNALBLOCKING''@|$(HAVE_POSIX_SIGNALBLOCKING)|g' \
              -e 's|@''HAVE_PTHREAD_SIGMASK''@|$(HAVE_PTHREAD_SIGMASK)|g' \
+             -e 's|@''HAVE_RAISE''@|$(HAVE_RAISE)|g' \
              -e 's|@''HAVE_SIGSET_T''@|$(HAVE_SIGSET_T)|g' \
              -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \
              -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \
@@ -41,6 +43,7 @@
              -e 
's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \
              -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \
              -e 's|@''REPLACE_PTHREAD_SIGMASK''@|$(REPLACE_PTHREAD_SIGMASK)|g' 
\
+             -e 's|@''REPLACE_RAISE''@|$(REPLACE_RAISE)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
--- tests/test-signal-c++.cc.orig       Sat Sep 24 00:44:10 2011
+++ tests/test-signal-c++.cc    Sat Sep 24 00:23:32 2011
@@ -29,6 +29,10 @@
                  (int, const sigset_t *, sigset_t *));
 #endif
 
+#if GNULIB_TEST_RAISE
+SIGNATURE_CHECK (GNULIB_NAMESPACE::raise, int, (int));
+#endif
+
 #if GNULIB_TEST_SIGPROCMASK
 SIGNATURE_CHECK (GNULIB_NAMESPACE::sigismember, int, (const sigset_t *, int));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::sigemptyset, int, (sigset_t *));

-- 
In memoriam Ghazala Khan <http://en.wikipedia.org/wiki/Ghazala_Khan>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]