master - libdm: config: remove 4096 char limit due to buffer size if writing dm_config_node
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=967a0889a024e2cc3f3afb3469e1b0657ebb85bc Commit: 967a0889a024e2cc3f3afb3469e1b0657ebb85bc Parent: 418b7c6be8e553c04eeeb8a96d6b3d4b1da1bb9a Author: Peter Rajnoha <[email protected]> AuthorDate: Fri Mar 4 14:59:22 2016 +0100 Committer: Peter Rajnoha <[email protected]> CommitterDate: Fri Mar 4 14:59:22 2016 +0100
libdm: config: remove 4096 char limit due to buffer size if writing dm_config_node
--- WHATS_NEW_DM | 1 + libdm/libdm-config.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
WHATS_NEW_DM +1 -0
@@ -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 =====================================
libdm/libdm-config.c +24 -2
@@ -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 ; }