[tor-commits] [tor/release-0.2.9] Use va_copy() in pure-windows version of tor_asprintf().

nickm at torproject.org nickm at torproject.org
Tue Nov 8 23:45:18 UTC 2016


commit 286fa94064dcc6d1b260bec77de052274e3c4403
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Nov 8 18:44:06 2016 -0500

    Use va_copy() in pure-windows version of tor_asprintf().
    
    It's not okay to use the same varargs list twice, and apparently
    some windows build environments produce code here that would leave
    tor_asprintf() broken. Fix for bug 20560; bugfix on 0.2.2.11-alpha
    when tor_asprintf() was introduced.
---
 changes/bug20560    | 4 ++++
 src/common/compat.c | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/changes/bug20560 b/changes/bug20560
new file mode 100644
index 0000000..43d605b
--- /dev/null
+++ b/changes/bug20560
@@ -0,0 +1,4 @@
+  o Minor bugfixes (portability):
+    - Run correctly when built on Windows build environments that require
+      _vcsprintf(). Fixes bug 20560; bugfix on 0.2.2.11-alpha.
+
diff --git a/src/common/compat.c b/src/common/compat.c
index 4f2f977..8d6a491 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -532,7 +532,10 @@ tor_vasprintf(char **strp, const char *fmt, va_list args)
   /* On Windows, _vsnprintf won't tell us the length of the string if it
    * overflows, so we need to use _vcsprintf to tell how much to allocate */
   int len, r;
-  len = _vscprintf(fmt, args);
+  va_list tmp_args;
+  va_copy(tmp_args, args);
+  len = _vscprintf(fmt, tmp_args);
+  va_end(tmp_args);
   if (len < 0) {
     *strp = NULL;
     return -1;





More information about the tor-commits mailing list