]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix backtrace compilation on FreeBSD
authorcypherpunks <cypherpunks@torproject.org>
Tue, 15 Dec 2015 15:30:04 +0000 (16:30 +0100)
committerNick Mathewson <nickm@torproject.org>
Tue, 15 Dec 2015 16:52:00 +0000 (11:52 -0500)
On FreeBSD backtrace(3) uses size_t instead of int (as glibc does). This
causes integer precision loss errors when we used int to store its
results.

The issue is fixed by using size_t to store the results of backtrace(3).

The manual page of glibc does not mention that backtrace(3) returns
negative values. Therefore, no unsigned integer wrapping occurs when its
result is stored in an unsigned data type.

changes/bug17827 [new file with mode: 0644]
src/common/backtrace.c
src/common/backtrace.h
src/common/sandbox.c

diff --git a/changes/bug17827 b/changes/bug17827
new file mode 100644 (file)
index 0000000..04cd3b5
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes (compilation):
+    - Fix backtrace compilation on FreeBSD. Fixes bug 17827; bugfix on
+      tor-0.2.5.2-alpha.
index a2d5378b204e50d08ba80067e30a23210637add1..8d544ed704bc3d2f54b4f27819851f8af8ea1a2d 100644 (file)
@@ -62,16 +62,16 @@ static tor_mutex_t cb_buf_mutex;
  * ucontext_t structure.
  */
 void
-clean_backtrace(void **stack, int depth, const ucontext_t *ctx)
+clean_backtrace(void **stack, size_t depth, const ucontext_t *ctx)
 {
 #ifdef PC_FROM_UCONTEXT
 #if defined(__linux__)
-  const int n = 1;
+  const size_t n = 1;
 #elif defined(__darwin__) || defined(__APPLE__) || defined(__OpenBSD__) \
   || defined(__FreeBSD__)
-  const int n = 2;
+  const size_t n = 2;
 #else
-  const int n = 1;
+  const size_t n = 1;
 #endif
   if (depth <= n)
     return;
@@ -89,9 +89,9 @@ clean_backtrace(void **stack, int depth, const ucontext_t *ctx)
 void
 log_backtrace(int severity, int domain, const char *msg)
 {
-  int depth;
+  size_t depth;
   char **symbols;
-  int i;
+  size_t i;
 
   tor_mutex_acquire(&cb_buf_mutex);
 
@@ -120,7 +120,7 @@ static void
 crash_handler(int sig, siginfo_t *si, void *ctx_)
 {
   char buf[40];
-  int depth;
+  size_t depth;
   ucontext_t *ctx = (ucontext_t *) ctx_;
   int n_fds, i;
   const int *fds = NULL;
@@ -174,7 +174,7 @@ install_bt_handler(void)
      * libc has pre-loaded the symbols we need to dump things, so that later
      * reads won't be denied by the sandbox code */
     char **symbols;
-    int depth = backtrace(cb_buf, MAX_DEPTH);
+    size_t depth = backtrace(cb_buf, MAX_DEPTH);
     symbols = backtrace_symbols(cb_buf, depth);
     if (symbols)
       free(symbols);
index a9151d795607c172e8f49af0f85079187cf81018..838e18eedd209c9ffac5a41fb7e667ec3b4b3bf9 100644 (file)
@@ -13,7 +13,7 @@ void clean_up_backtrace_handler(void);
 #ifdef EXPOSE_CLEAN_BACKTRACE
 #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && \
   defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_SIGACTION)
-void clean_backtrace(void **stack, int depth, const ucontext_t *ctx);
+void clean_backtrace(void **stack, size_t depth, const ucontext_t *ctx);
 #endif
 #endif
 
index b995762738ae7719a35ff4f07af98c3c4cddd477..3a9f2a1898ad40119869694d433e5930734b120a 100644 (file)
@@ -1598,7 +1598,7 @@ sigsys_debugging(int nr, siginfo_t *info, void *void_context)
   const char *syscall_name;
   int syscall;
 #ifdef USE_BACKTRACE
-  int depth;
+  size_t depth;
   int n_fds, i;
   const int *fds = NULL;
 #endif