[tor-commits] [obfsproxy/master] Use va_copy; do not use the same va_list twice. fix bug 5078

nickm at torproject.org nickm at torproject.org
Fri Feb 10 19:49:33 UTC 2012


commit a195187bfaea90324179a18aa87df2628d6b4ec3
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Feb 10 12:36:58 2012 -0500

    Use va_copy; do not use the same va_list  twice. fix bug 5078
---
 configure.ac  |   15 +++++++++++++++
 src/managed.c |   11 +++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 3809750..4105990 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,21 @@ LIBS="$save_LIBS"
 AC_C_INLINE
 AC_CHECK_SIZEOF(int)
 
+dnl check for working va_copy. It could be a function or a macro.
+AC_MSG_CHECKING([whether we have va_copy])
+AC_CACHE_VAL(obfs_cv_have_vacopy,
+  AC_TRY_LINK([#include <stdarg.h>], [
+    va_list ap, ap2;
+    va_copy(ap, ap2);
+  ], [obfs_cv_have_vacopy=true],
+     [obfs_cv_have_vacopy=false]))
+if test "$obfs_cv_have_vacopy" = true; then
+  AC_DEFINE(HAVE_VA_COPY, 1, [True if this platform has the standard va_copy macro])
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_RESULT(no)
+fi
+
 ### Output ###
 
 AC_CONFIG_FILES([Makefile])
diff --git a/src/managed.c b/src/managed.c
index dfd8a3f..01814f8 100644
--- a/src/managed.c
+++ b/src/managed.c
@@ -142,16 +142,23 @@ log_proxy_env(managed_proxy_t *proxy)
 static void
 print_protocol_line(const char *format, ...)
 {
-  va_list ap;
+  va_list ap, ap2;
   va_start(ap,format);
+#ifdef HAVE_VA_COPY
+  va_copy(ap2, ap);
+#else
+  memcpy(&ap2, &ap, sizeof(ap));
+#endif
+
   vprintf(format, ap);
   fflush(stdout);
 
   /* log the protocol message */
   log_debug("We sent:");
-  log_debug_raw(format, ap);
+  log_debug_raw(format, ap2);
 
   va_end(ap);
+  va_end(ap2);
 }
 
 /**





More information about the tor-commits mailing list