1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

libdm: config: remove 4096 char limit due to buffer size if writing dm_config_node

This commit is contained in:
Peter Rajnoha 2016-03-04 14:59:22 +01:00
parent 418b7c6be8
commit 967a0889a0
2 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.119 - Version 1.02.119 -
===================================== =====================================
Remove 4096 char limit due to buffer size if writing dm_config_node.
Version 1.02.118 - 26th February 2016 Version 1.02.118 - 26th February 2016
===================================== =====================================

View File

@ -222,19 +222,41 @@ __attribute__ ((format(printf, 2, 3)))
static int _line_append(struct config_output *out, const char *fmt, ...) static int _line_append(struct config_output *out, const char *fmt, ...)
{ {
char buf[4096]; char buf[4096];
char *final_buf;
va_list ap; va_list ap;
int n; int n;
/*
* We should be fine with the 4096 char buffer 99% of the time,
* but if we need to go beyond that, allocate the buffer dynamically.
*/
va_start(ap, fmt); va_start(ap, fmt);
n = vsnprintf(&buf[0], sizeof buf - 1, fmt, ap); n = vsnprintf(&buf[0], sizeof buf - 1, fmt, ap);
va_end(ap); va_end(ap);
if (n < 0 || n > (int) sizeof buf - 1) { if (n < 0) {
log_error("vsnprintf failed for config line"); log_error("vsnprintf failed for config line");
return 0; return 0;
} }
if (!dm_pool_grow_object(out->mem, &buf[0], strlen(buf))) { if (n > (int) sizeof buf - 1) {
/*
* Fixed size buffer with sizeof buf is not enough,
* so try dynamically allocated buffer now...
*/
va_start(ap, fmt);
n = dm_vasprintf(&final_buf, fmt, ap);
va_end(ap);
if (n < 0) {
log_error("dm_vasprintf failed for config line");
return 0;
}
} else
final_buf = buf;
if (!dm_pool_grow_object(out->mem, final_buf, strlen(final_buf))) {
log_error("dm_pool_grow_object failed for config line"); log_error("dm_pool_grow_object failed for config line");
return 0; return 0;
} }