* [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* [PATCH v2] [DEBUG] Use va_copy when reusing a va_list
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
2011-03-15 8:04 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Nieder @ 2011-03-14 6:29 UTC (permalink / raw)
To: dash
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
^ 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