sig{set,long}jmp: do not ignore sigsetjmp's second argument
authormirabilos <tg@debian.org>
Wed, 5 May 2021 19:02:37 +0000 (21:02 +0200)
committerBen Hutchings <benh@debian.org>
Sun, 26 Dec 2021 23:17:05 +0000 (23:17 +0000)
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=eb10cf8c3128612a089ace8489a81bc4ffd5d07a
Bug-Debian: https://bugs.debian.org/988027

Save and restore the signal mask only if that argument is nonzero,
as required by the standards.  (Closes: Debian #988027)

Signed-off-by: mirabilos <tg@debian.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name sig-set-long-jmp-do-not-ignore-sigsetjmp-s-second-ar.patch

usr/include/setjmp.h
usr/klibc/CAVEATS
usr/klibc/siglongjmp.c

index abebccde4fe2d109971ff9c44e2437ea0cd73cd9..5916cd8a32948ac43eabbd9bda7898f07ed76d29 100644 (file)
@@ -27,6 +27,7 @@ __extern __noreturn longjmp(jmp_buf, int);
 struct __sigjmp_buf {
        jmp_buf __jmpbuf;
        sigset_t __sigs;
+       unsigned char __sigs_saved;
 };
 
 typedef struct __sigjmp_buf sigjmp_buf[1];
@@ -34,7 +35,11 @@ typedef struct __sigjmp_buf sigjmp_buf[1];
 #define sigsetjmp(__env, __save) \
 ({ \
   struct __sigjmp_buf *__e = (__env); \
-  sigprocmask(0, NULL, &__e->__sigs); \
+  if (__save) { \
+    sigprocmask(0, NULL, &__e->__sigs); \
+    __e->__sigs_saved = 1; \
+  } else \
+    __e->__sigs_saved = 0; \
   setjmp(__e->__jmpbuf); \
 })
 
index 5e991cb7b69cbe2247ab29e773596a0b8536b39c..39949c28ac8ff23ed7fc337919388c35739992d7 100644 (file)
@@ -13,8 +13,7 @@ Compiling with -O0 is more likely to work on gcc 3.
 setjmp()/longjmp():
 -------------------
 setjmp() and longjmp() *do not* save signal state.  sigsetjmp() and
-siglongjmp() *do* save the signal mask -- regardless of the value of
-the extra argument.
+siglongjmp() *do* save the signal mask if the extra argument is nonzero.
 
 The standards actually state that if you pass longjmp() a final value
 of zero the library should change that to a 1!  Presumably the reason
index 31042cbd90ba4436cc97bdecf0958d464879d4bf..45f4e400e00c97cfd56abb5ea5b81a53c7db1b0e 100644 (file)
@@ -10,6 +10,7 @@
 
 __noreturn siglongjmp(sigjmp_buf buf, int retval)
 {
-       sigprocmask(SIG_SETMASK, &buf->__sigs, NULL);
+       if (buf->__sigs_saved)
+               sigprocmask(SIG_SETMASK, &buf->__sigs, NULL);
        longjmp(buf->__jmpbuf, retval);
 }