]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Fixed undefined behavior on signals.
authorMaria Matejka <mq@ucw.cz>
Fri, 4 Oct 2019 10:20:02 +0000 (12:20 +0200)
committerMaria Matejka <mq@jmq.cz>
Fri, 4 Oct 2019 19:00:40 +0000 (21:00 +0200)
The C11 specification allows only sig_atomic_t and _Atomic variable
access. All other accesses to global variables are undefined behavior.

Using int was probably OK on x86 and x86_64; yet there were some reports
from other architectures (especially some MIPS) that in rare cases,
after issuing SIGHUP, BIRD did strange things.

sysdep/unix/io.c
sysdep/unix/main.c
sysdep/unix/unix.h
test/birdtest.c

index 8f76652ade592853f89da071014d14f7551bfc1a..d2f1f205bf3783396ef8ccd0ae4e35ad2c01975b 100644 (file)
@@ -2144,10 +2144,6 @@ watchdog_stop(void)
  *     Main I/O Loop
  */
 
-volatile int async_config_flag;                /* Asynchronous reconfiguration/dump scheduled */
-volatile int async_dump_flag;
-volatile int async_shutdown_flag;
-
 void
 io_init(void)
 {
index a898a19a803d225755f14a1d4fbdac69d4c00cc7..0624e7b371797c9fa287fcc6cc58f256d35a1700 100644 (file)
@@ -583,9 +583,9 @@ cmd_graceful_restart(void)
  *     Signals
  */
 
-volatile int async_config_flag;
-volatile int async_dump_flag;
-volatile int async_shutdown_flag;
+volatile sig_atomic_t async_config_flag;
+volatile sig_atomic_t async_dump_flag;
+volatile sig_atomic_t async_shutdown_flag;
 
 static void
 handle_sighup(int sig UNUSED)
index 7e3a9fede072601f3f25865b0a40ffe87833e71c..1490243cb2589c644e15b89fce72a904d26c10aa 100644 (file)
@@ -10,6 +10,7 @@
 #define _BIRD_UNIX_H_
 
 #include <sys/socket.h>
+#include <signal.h>
 
 struct pool;
 struct iface;
@@ -96,9 +97,9 @@ int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *po
 #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path))
 #endif
 
-extern volatile int async_config_flag;
-extern volatile int async_dump_flag;
-extern volatile int async_shutdown_flag;
+extern volatile sig_atomic_t async_config_flag;
+extern volatile sig_atomic_t async_dump_flag;
+extern volatile sig_atomic_t async_shutdown_flag;
 
 void io_init(void);
 void io_loop(void);
index 823b02ff616c78564c0b75279888b7edd833f9d5..ede4eb5279420f400044a6041f29bfa244b70451 100644 (file)
@@ -35,6 +35,11 @@ static int no_fork;
 static int no_timeout;
 static int is_terminal;                /* Whether stdout is a live terminal or pipe redirect */
 
+volatile sig_atomic_t async_config_flag;               /* Asynchronous reconfiguration/dump scheduled */
+volatile sig_atomic_t async_dump_flag;
+volatile sig_atomic_t async_shutdown_flag;
+
+
 uint bt_verbose;
 const char *bt_filename;
 const char *bt_test_id;