1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

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
This commit is contained in:
Zdenek Kabelac 2014-09-15 15:33:56 +02:00
parent b9c16b7506
commit 1ce21c19d5
3 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.112 - Version 2.02.112 -
===================================== =====================================
Use va_copy to properly pass va_list through functions.
Add function to detect rotational devices. Add function to detect rotational devices.
Review internal checks for mirror/raid/pvmove volumes. Review internal checks for mirror/raid/pvmove volumes.
Track mirror segment type with separate MIRROR flag. Track mirror segment type with separate MIRROR flag.

View File

@ -190,9 +190,12 @@ static int _out_with_comment_raw(struct formatter *f,
const char *fmt, va_list ap) const char *fmt, va_list ap)
{ {
int n; int n;
va_list apc;
va_copy(apc, ap);
n = vsnprintf(f->data.buf.start + f->data.buf.used, 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 metadata doesn't fit, extend buffer */
if (n < 0 || (n + f->data.buf.used + 2 > f->data.buf.size)) { if (n < 0 || (n + f->data.buf.used + 2 > f->data.buf.size)) {

View File

@ -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 }; static const daemon_reply err = { .error = ENOMEM };
daemon_request rq = { .cft = NULL }; daemon_request rq = { .cft = NULL };
daemon_reply repl; daemon_reply repl;
va_list apc;
va_copy(apc, ap);
if (!buffer_append_f(&rq.buffer, "request = %s", id, NULL) || 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); buffer_destroy(&rq.buffer);
return err; return err;
} }
va_end(apc);
repl = daemon_send(h, rq); repl = daemon_send(h, rq);
buffer_destroy(&rq.buffer); buffer_destroy(&rq.buffer);
@ -181,13 +185,17 @@ bad:
int daemon_request_extend_v(daemon_request r, va_list ap) int daemon_request_extend_v(daemon_request r, va_list ap)
{ {
int res;
va_list apc;
if (!r.cft) if (!r.cft)
return 0; return 0;
if (!config_make_nodes_v(r.cft, NULL, r.cft->root, ap)) va_copy(apc, ap);
return 0; 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, ...) int daemon_request_extend(daemon_request r, ...)