[tor-commits] [tor/master] Refrain from using static buffer for assert failure message; call tor_asprintf() instead

nickm at torproject.org nickm at torproject.org
Fri Mar 29 19:55:22 UTC 2019


commit 9c132a5f9e87a2cd0f59bd8d21226ba2256f7bce
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Fri Mar 22 13:44:02 2019 +0200

    Refrain from using static buffer for assert failure message; call tor_asprintf() instead
---
 src/lib/log/util_bug.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/lib/log/util_bug.c b/src/lib/log/util_bug.c
index 1ce48c0eb..e5d5a2958 100644
--- a/src/lib/log/util_bug.c
+++ b/src/lib/log/util_bug.c
@@ -74,7 +74,7 @@ tor_assertion_failed_(const char *fname, unsigned int line,
                       const char *func, const char *expr,
                       const char *fmt, ...)
 {
-  char buf[256];
+  char *buf = NULL;
   char *extra = NULL;
   va_list ap;
 
@@ -93,11 +93,11 @@ tor_assertion_failed_(const char *fname, unsigned int line,
 
   log_err(LD_BUG, "%s:%u: %s: Assertion %s failed; aborting.",
           fname, line, func, expr);
-  tor_snprintf(buf, sizeof(buf),
-               "Assertion %s failed in %s at %s:%u: %s",
+  tor_asprintf(&buf, "Assertion %s failed in %s at %s:%u: %s",
                expr, func, fname, line, extra ? extra : "");
   tor_free(extra);
   log_backtrace(LOG_ERR, LD_BUG, buf);
+  tor_free(buf);
 }
 
 /** Helper for tor_assert_nonfatal: report the assertion failure. */
@@ -107,7 +107,7 @@ tor_bug_occurred_(const char *fname, unsigned int line,
                   const char *func, const char *expr,
                   int once, const char *fmt, ...)
 {
-  char buf[256];
+  char *buf = NULL;
   const char *once_str = once ?
     " (Future instances of this warning will be silenced.)": "";
   if (! expr) {
@@ -144,12 +144,12 @@ tor_bug_occurred_(const char *fname, unsigned int line,
 
     log_warn(LD_BUG, "%s:%u: %s: Non-fatal assertion %s failed.%s",
              fname, line, func, expr, once_str);
-    tor_snprintf(buf, sizeof(buf),
-                 "Non-fatal assertion %s failed in %s at %s:%u%s%s",
+    tor_asprintf(&buf, "Non-fatal assertion %s failed in %s at %s:%u%s%s",
                  expr, func, fname, line, fmt ? " : " : "", extra);
     tor_free(extra);
   }
   log_backtrace(LOG_WARN, LD_BUG, buf);
+  tor_free(buf);
 
 #ifdef TOR_UNIT_TESTS
   if (failed_assertion_cb) {





More information about the tor-commits mailing list