[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/maint-0.3.5] Use a tor_abort_() wrapper in our util_bug.h macros



commit 802ac8ad618a0674c26bb973a2277e07b20f8c7b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Mon Apr 15 14:16:23 2019 -0400

    Use a tor_abort_() wrapper in our util_bug.h macros
    
    Previously, our use of abort() would break anywhere that we didn't
    include stdlib.h.  This was especially troublesome in case where
    tor_assert_nonfatal() was used with ALL_BUGS_ARE_FATAL, since that
    one seldom gets tested.
    
    As an alternative, we could have just made this header include
    stdlib.h.  But that seems bloaty.
    
    Fixes bug 30189; bugfix on 0.3.4.1-alpha.
---
 changes/bug30189       |  4 ++++
 src/lib/log/util_bug.c | 14 ++++++++++++++
 src/lib/log/util_bug.h |  8 +++++---
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/changes/bug30189 b/changes/bug30189
new file mode 100644
index 000000000..f8c932a5f
--- /dev/null
+++ b/changes/bug30189
@@ -0,0 +1,4 @@
+  o Minor bugfixes (compilation, unusual configuration):
+    - Avoid failures when building with ALL_BUGS_ARE_FAILED due to
+      missing declarations of abort(), and prevent other such failures
+      in the future. Fixes bug 30189; bugfix on 0.3.4.1-alpha.
diff --git a/src/lib/log/util_bug.c b/src/lib/log/util_bug.c
index f42d2d2ab..c65a91ae9 100644
--- a/src/lib/log/util_bug.c
+++ b/src/lib/log/util_bug.c
@@ -19,6 +19,7 @@
 #include "lib/string/printf.h"
 
 #include <string.h>
+#include <stdlib.h>
 
 #ifdef TOR_UNIT_TESTS
 static void (*failed_assertion_cb)(void) = NULL;
@@ -120,6 +121,19 @@ tor_bug_occurred_(const char *fname, unsigned int line,
 #endif
 }
 
+/**
+ * Call the abort() function to kill the current process with a fatal
+ * error.
+ *
+ * (This is a separate function so that we declare it in util_bug.h without
+ * including stdlib in all the users of util_bug.h)
+ **/
+void
+tor_abort_(void)
+{
+  abort();
+}
+
 #ifdef _WIN32
 /** Take a filename and return a pointer to its final element.  This
  * function is called on __FILE__ to fix a MSVC nit where __FILE__
diff --git a/src/lib/log/util_bug.h b/src/lib/log/util_bug.h
index 18d40bbf3..2a4d68127 100644
--- a/src/lib/log/util_bug.h
+++ b/src/lib/log/util_bug.h
@@ -99,7 +99,7 @@
   if (ASSERT_PREDICT_LIKELY_(expr)) {                                   \
   } else {                                                              \
     tor_assertion_failed_(SHORT_FILE__, __LINE__, __func__, #expr);     \
-    abort();                                                            \
+    tor_abort_();                                                       \
   } STMT_END
 #endif /* defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS) */
 
@@ -107,7 +107,7 @@
   STMT_BEGIN {                                                  \
     tor_assertion_failed_(SHORT_FILE__, __LINE__, __func__,     \
                           "line should be unreached");          \
-    abort();                                                    \
+    tor_abort_();                                               \
   } STMT_END
 
 /* Non-fatal bug assertions. The "unreached" variants mean "this line should
@@ -141,7 +141,7 @@
 #define BUG(cond)                                                       \
   (ASSERT_PREDICT_UNLIKELY_(cond) ?                                     \
    (tor_assertion_failed_(SHORT_FILE__,__LINE__,__func__,"!("#cond")"), \
-    abort(), 1)                                                         \
+    tor_abort_(), 1)                                                    \
    : 0)
 #elif defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
 #define tor_assert_nonfatal_unreached() STMT_NIL
@@ -226,6 +226,8 @@ void tor_bug_occurred_(const char *fname, unsigned int line,
                        const char *func, const char *expr,
                        int once);
 
+void tor_abort_(void) ATTR_NORETURN;
+
 #ifdef _WIN32
 #define SHORT_FILE__ (tor_fix_source_file(__FILE__))
 const char *tor_fix_source_file(const char *fname);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits