diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2016-03-04 14:59:22 +0100 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-03-04 14:59:22 +0100 |
commit | 967a0889a024e2cc3f3afb3469e1b0657ebb85bc (patch) | |
tree | e1c797b5f424cb1b1a325cb37f21850a38b0f5ee | |
parent | 418b7c6be8e553c04eeeb8a96d6b3d4b1da1bb9a (diff) | |
download | lvm2-967a0889a024e2cc3f3afb3469e1b0657ebb85bc.tar.gz |
libdm: config: remove 4096 char limit due to buffer size if writing dm_config_node
-rw-r--r-- | WHATS_NEW_DM | 1 | ||||
-rw-r--r-- | libdm/libdm-config.c | 26 |
2 files changed, 25 insertions, 2 deletions
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 174b6bd7c..d3eac299b 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.119 - ===================================== + Remove 4096 char limit due to buffer size if writing dm_config_node. Version 1.02.118 - 26th February 2016 ===================================== diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c index 25f85e564..a7f409635 100644 --- a/libdm/libdm-config.c +++ b/libdm/libdm-config.c @@ -222,19 +222,41 @@ __attribute__ ((format(printf, 2, 3))) static int _line_append(struct config_output *out, const char *fmt, ...) { char buf[4096]; + char *final_buf; va_list ap; 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); n = vsnprintf(&buf[0], sizeof buf - 1, fmt, ap); va_end(ap); - if (n < 0 || n > (int) sizeof buf - 1) { + if (n < 0) { log_error("vsnprintf failed for config line"); 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"); return 0; } |