mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-17 06:04:23 +03:00
lvmetad: validate dm_asprintf in buffer_append_vf
Check result of dm_asprintf Check buffer_append result Declare vars in front
This commit is contained in:
parent
5c792f620b
commit
f2a5d3ae3a
@ -23,9 +23,12 @@
|
|||||||
|
|
||||||
int buffer_append_vf(struct buffer *buf, va_list ap)
|
int buffer_append_vf(struct buffer *buf, va_list ap)
|
||||||
{
|
{
|
||||||
char *append;
|
char *append = NULL;
|
||||||
char *next;
|
char *next;
|
||||||
int keylen;
|
int keylen;
|
||||||
|
int64_t value;
|
||||||
|
char *string;
|
||||||
|
char *block;
|
||||||
|
|
||||||
while ((next = va_arg(ap, char *))) {
|
while ((next = va_arg(ap, char *))) {
|
||||||
if (!strchr(next, '=')) {
|
if (!strchr(next, '=')) {
|
||||||
@ -34,21 +37,25 @@ int buffer_append_vf(struct buffer *buf, va_list ap)
|
|||||||
}
|
}
|
||||||
keylen = strchr(next, '=') - next;
|
keylen = strchr(next, '=') - next;
|
||||||
if (strstr(next, "%d") || strstr(next, "%" PRId64)) {
|
if (strstr(next, "%d") || strstr(next, "%" PRId64)) {
|
||||||
int64_t value = va_arg(ap, int64_t);
|
value = va_arg(ap, int64_t);
|
||||||
dm_asprintf(&append, "%.*s= %" PRId64 "\n", keylen, next, value);
|
if (!dm_asprintf(&append, "%.*s= %" PRId64 "\n", keylen, next, value) < 0)
|
||||||
|
goto fail;
|
||||||
} else if (strstr(next, "%s")) {
|
} else if (strstr(next, "%s")) {
|
||||||
char *value = va_arg(ap, char *);
|
string = va_arg(ap, char *);
|
||||||
dm_asprintf(&append, "%.*s= \"%s\"\n", keylen, next, value);
|
if (!dm_asprintf(&append, "%.*s= \"%s\"\n", keylen, next, string) < 0)
|
||||||
|
goto fail;
|
||||||
} else if (strstr(next, "%b")) {
|
} else if (strstr(next, "%b")) {
|
||||||
char *block = va_arg(ap, char *);
|
if (!(block = va_arg(ap, char *)))
|
||||||
if (!block)
|
|
||||||
continue;
|
continue;
|
||||||
dm_asprintf(&append, "%.*s%s", keylen, next, block);
|
if (!dm_asprintf(&append, "%.*s%s", keylen, next, block) < 0)
|
||||||
} else {
|
goto fail;
|
||||||
dm_asprintf(&append, "%s", next);
|
} else if (!dm_asprintf(&append, "%s", next) < 0)
|
||||||
}
|
goto fail;
|
||||||
if (!append) goto fail;
|
|
||||||
buffer_append(buf, append);
|
if (!append ||
|
||||||
|
!buffer_append(buf, append))
|
||||||
|
return 0;
|
||||||
|
|
||||||
dm_free(append);
|
dm_free(append);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user