summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-03-15 16:03:47 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2011-03-15 16:03:47 +0800
commitfd45f364a8387f7193f2b9be5d316ffb4361a5da (patch)
treec81bb63705ec933ccdfcaabd39bb8f74cbd1d42d
parent[EXPAND] Free IFS state after here document expansion (diff)
downloaddash-fd45f364a8387f7193f2b9be5d316ffb4361a5da.tar.gz
dash-fd45f364a8387f7193f2b9be5d316ffb4361a5da.zip
[DEBUG] Use va_copy when reusing a va_list
When tracing (with the DEBUG compile-time option set to 1 or 2),
exverror calls TRACEV to print its arguments before passing them on.
So the arguments are consumed by the time exvwarning looks for them,
resulting in a segfault:

 $ sh -c '"'
 sh: Syntax error: Unterminated quoted string
 $ sh -o debug -c '"'
 sh: Segmentation fault (core dumped)

Make a copy with va_copy to avoid this.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--ChangeLog1
-rw-r--r--src/error.c5
2 files changed, 5 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 5163479..5b6d53e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2011-03-15  Jonathan Nieder <jrnieder@gmail.com>
 
 	* Free IFS state after here document expansion.
+	* Use va_copy when reusing a va_list.
 
 2011-03-15  Harald van Dijk <harald@gigawatt.nl>
 
diff --git a/src/error.c b/src/error.c
index 7ad73bc..9d31989 100644
--- a/src/error.c
+++ b/src/error.c
@@ -143,8 +143,11 @@ exverror(int cond, const char *msg, va_list ap)
 {
 #ifdef DEBUG
 	if (msg) {
+		va_list aq;
 		TRACE(("exverror(%d, \"", cond));
-		TRACEV((msg, ap));
+		va_copy(aq, ap);
+		TRACEV((msg, aq));
+		va_end(aq);
 		TRACE(("\") pid=%d\n", getpid()));
 	} else
 		TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));