From 11e2edcf5f93b242660b250afbf0c2b30c9c2378 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Mon, 20 Sep 2010 14:25:27 +0000 Subject: [PATCH] Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function. Revert to old glibc behaviour for vsnprintf used in emit_to_buffer fn. Otherwise, the check that follows would be wrong for new glibc versions. This caused the rh bug #633033 to be undetected and pass throught the check, corrupting the metadata! --- WHATS_NEW | 1 + lib/misc/lvm-string.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/WHATS_NEW b/WHATS_NEW index 895621ca2..20f4e4837 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.74 - ================================== + Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function. Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit). Add random suffix to archive file names to prevent races when being created. Reinitialize archive and backup handling on toolcontext refresh. diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c index 7eed79951..82a3e948c 100644 --- a/lib/misc/lvm-string.c +++ b/lib/misc/lvm-string.c @@ -27,6 +27,14 @@ int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...) n = vsnprintf(*buffer, *size, fmt, ap); va_end(ap); + /* + * Revert to old glibc behaviour (version <= 2.0.6) where snprintf + * returned -1 if buffer was too small. From glibc 2.1 it returns number + * of chars that would have been written had there been room. + */ + if (n < 0 || ((unsigned) n + 1 > *size)) + n = -1; + if (n < 0 || ((size_t)n == *size)) return 0; -- 2.43.5