master - va_list: properly pass va_list through functions
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1ce21c19d5894b889a6d8da67c8a159709c3dda9 Commit: 1ce21c19d5894b889a6d8da67c8a159709c3dda9 Parent: b9c16b750694c4ec03d05bc9e4a12cecc4d9450f Author: Zdenek Kabelac <[email protected]> AuthorDate: Mon Sep 15 15:33:56 2014 +0200 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Tue Sep 16 11:42:40 2014 +0200
va_list: properly pass va_list through functions
Code should not just pass va_list arg through the function as args could be passed in many strange ways.
Use va_copy().
For details look in i.e.:
http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html
--- WHATS_NEW | 1 + lib/format_text/export.c | 5 ++++- libdaemon/client/daemon-client.c | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-)
WHATS_NEW +1 -0
@@ -1,5 +1,6 @@ Version 2.02.112 - ===================================== + Use va_copy to properly pass va_list through functions. Add function to detect rotational devices. Review internal checks for mirror/raid/pvmove volumes. Track mirror segment type with separate MIRROR flag.
lib/format_text/export.c +4 -1
@@ -190,9 +190,12 @@ static int _out_with_comment_raw(struct formatter *f, const char *fmt, va_list ap) { int n; +va_list apc; +va_copy (apc, ap); n =vsnprintf (f->data.buf.start + f->data.buf.used, - f->data.buf.size - f->data.buf.used, fmt, ap); + f->data.buf.size - f->data.buf.used, fmt, apc); +va_end (apc);/* If metadata doesn't fit, extend buffer */ if (n <0 || (n + f->data.buf.used +2 > f->data.buf.size)) {
libdaemon/client/daemon-client.c +12 -4
@@ -129,12 +129,16 @@ daemon_reply daemon_send_simple_v(daemon_handle h, const char *id, va_list ap)static const daemon_reply err = { .error =ENOMEM };daemon_request rq = { .cft =NULL };daemon_reply repl; +va_list apc; +va_copy (apc, ap);if (!buffer_append_f (&rq.buffer,"request = %s" , id,NULL ) || - !buffer_append_vf (&rq.buffer, ap)) { + !buffer_append_vf (&rq.buffer, apc)) { +va_end (apc);buffer_destroy (&rq.buffer);return err; } +va_end (apc); repl =daemon_send (h, rq);buffer_destroy (&rq.buffer);
@@ -181,13 +185,17 @@ bad:int daemon_request_extend_v (daemon_request r,va_list ap) { +int res; +va_list apc; +if (!r.cft)return 0 ; -if (!config_make_nodes_v (r.cft,NULL , r.cft->root, ap)) -return 0 ; +va_copy (apc, ap); + res =config_make_nodes_v (r.cft,NULL , r.cft->root, apc) ?1 :0 ; +va_end (apc); -return 1 ; +return res; }int daemon_request_extend (daemon_request r, ...)