All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function
@ 2010-09-13 14:36 Peter Rajnoha
  2010-09-20 12:35 ` Alasdair G Kergon
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Rajnoha @ 2010-09-13 14:36 UTC (permalink / raw)
  To: lvm-devel

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(-)

diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c
index 7eed799..82a3e94 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;
 



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function
  2010-09-13 14:36 [PATCH] Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function Peter Rajnoha
@ 2010-09-20 12:35 ` Alasdair G Kergon
  0 siblings, 0 replies; 2+ messages in thread
From: Alasdair G Kergon @ 2010-09-20 12:35 UTC (permalink / raw)
  To: lvm-devel

On Mon, Sep 13, 2010 at 04:36:10PM +0200, Peter Rajnoha wrote:
> 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-20 12:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-13 14:36 [PATCH] Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function Peter Rajnoha
2010-09-20 12:35 ` Alasdair G Kergon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.