DASH Shell discussions
 help / color / mirror / Atom feed
* [PATCH] [DEBUG] Use va_copy when we use va_list twice
@ 2011-03-13 16:33 Jonathan Nieder
  2011-03-14  6:29 ` [PATCH v2] [DEBUG] Use va_copy when reusing a va_list Jonathan Nieder
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Nieder @ 2011-03-13 16:33 UTC (permalink / raw)
  To: dash

When tracing (if the DEBUG compile-time option was set to 1 or 2),
exverror calls TRACEV to print its arguments before passing them on to
exvwarning.  That consumes the arguments, resulting in a segfault:

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

Making a copy with va_copy fixes it.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Ran into this while tracking down a potential ifs leak from
<http://bugs.debian.org/618023>.

 src/error.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/error.c b/src/error.c
index f1a358d..e51d827 100644
--- a/src/error.c
+++ b/src/error.c
@@ -143,8 +143,10 @@ exverror(int cond, const char *msg, va_list ap)
 {
 #ifdef DEBUG
 	if (msg) {
+		va_list aq;
+		va_copy(aq, ap);
 		TRACE(("exverror(%d, \"", cond));
-		TRACEV((msg, ap));
+		TRACEV((msg, aq));
 		TRACE(("\") pid=%d\n", getpid()));
 	} else
 		TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-15  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-13 16:33 [PATCH] [DEBUG] Use va_copy when we use va_list twice Jonathan Nieder
2011-03-14  6:29 ` [PATCH v2] [DEBUG] Use va_copy when reusing a va_list Jonathan Nieder
2011-03-15  8:04   ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox