1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm: validate vsnprintf

Avoid using buffer when no output has been generated.
Missed in ee13f265f0.
This commit is contained in:
Zdenek Kabelac 2016-12-09 22:54:08 +01:00
parent 3903f915f8
commit 6f84d3c69c
2 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.138 - Version 1.02.138 -
===================================== =====================================
Validation vsnprintf result in runtime translate of dm_log (1.02.136).
Separate filemap extent allocation from region table. Separate filemap extent allocation from region table.
Fix segmentation fault when filemap region creation fails Fix segmentation fault when filemap region creation fails
Fix performance of region cleanup for failed filemap creation. Fix performance of region cleanup for failed filemap creation.

View File

@ -173,13 +173,15 @@ static void _log_to_default_log(int level,
const char *file, int line, int dm_errno_or_class, const char *file, int line, int dm_errno_or_class,
const char *f, ...) const char *f, ...)
{ {
int n;
va_list ap; va_list ap;
char buf[2 * PATH_MAX + 256]; /* big enough for most messages */ char buf[2 * PATH_MAX + 256]; /* big enough for most messages */
va_start(ap, f); va_start(ap, f);
vsnprintf(buf, sizeof(buf), f, ap); n = vsnprintf(buf, sizeof(buf), f, ap);
va_end(ap); va_end(ap);
if (n > 0) /* Could be truncated */
dm_log(level, file, line, "%s", buf); dm_log(level, file, line, "%s", buf);
} }
@ -195,13 +197,15 @@ __attribute__((format(printf, 4, 5)))
static void _log_to_default_log_with_errno(int level, static void _log_to_default_log_with_errno(int level,
const char *file, int line, const char *f, ...) const char *file, int line, const char *f, ...)
{ {
int n;
va_list ap; va_list ap;
char buf[2 * PATH_MAX + 256]; /* big enough for most messages */ char buf[2 * PATH_MAX + 256]; /* big enough for most messages */
va_start(ap, f); va_start(ap, f);
vsnprintf(buf, sizeof(buf), f, ap); n = vsnprintf(buf, sizeof(buf), f, ap);
va_end(ap); va_end(ap);
if (n > 0) /* Could be truncated */
dm_log_with_errno(level, file, line, 0, "%s", buf); dm_log_with_errno(level, file, line, 0, "%s", buf);
} }