Use va_copy when we use va_list twice
PATCH 1/1 Use va_copy when we use va_list twice
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.
---
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(-)
src/error.c +3 -1
@@ -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 ()));
Signature · 1 line
1.7.4.1
PATCH v2 1/1 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.
---
v1 left out va_end. Sorry for the nonsense.
src/error.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
src/error.c +4 -1
@@ -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 ()));
Signature · 1 line
1.7.4.1
Re: [PATCH v2] [DEBUG] Use va_copy when reusing a va_list
Quoted 5 lines · Jonathan Nieder
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:
Quoted 8 lines
$ sh -c '"' sh: Syntax error: Unterminated quoted string $ sh -o debug -c '"' sh: Segmentation fault (core dumped)Make a copy with
va_copyto avoid this.Signed-off-by Jonathan Nieder <[email protected]>
Also applied.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt