Skip to contentSkip to conversation

Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function

PATCH New Peter Rajnoha 2 participants 2 messages Sep 13, 2010 – Sep 20, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 bug #633033 to be undetected and pass throught the check, corrupting the metadata!)

Peter

---
 lib/misc/lvm-string.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
lib/misc/lvm-string.c +8 -0
index 7eed799..82a3e94 100644
@@ -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;
 
#1 lore raw

PATCH 1/1 Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function

Quoted 2 lines · Peter Rajnoha

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.

Ack.

Alasdair