DASH Shell discussions
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: dash@vger.kernel.org
Subject: [PATCH v2] [DEBUG] Use va_copy when reusing a va_list
Date: Mon, 14 Mar 2011 01:29:27 -0500	[thread overview]
Message-ID: <20110314062909.GA18712@elie> (raw)
In-Reply-To: <20110313163259.GA24451@elie>

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>
---
v1 left out va_end.  Sorry for the nonsense.

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

diff --git a/src/error.c b/src/error.c
index f1a358d..db2eb62 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()));
-- 
1.7.4.1


  reply	other threads:[~2011-03-14  6:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-13 16:33 [PATCH] [DEBUG] Use va_copy when we use va_list twice Jonathan Nieder
2011-03-14  6:29 ` Jonathan Nieder [this message]
2011-03-15  8:04   ` [PATCH v2] [DEBUG] Use va_copy when reusing a va_list Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110314062909.GA18712@elie \
    --to=jrnieder@gmail.com \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox