Blame SOURCES/0032-rasdaemon-handle-failures-of-snprintf.patch

97e186
From 59f6c44864f914a189cb924dd8fea14cc314bf3f Mon Sep 17 00:00:00 2001
97e186
From: Aristeu Rozanski <arozansk@redhat.com>
97e186
Date: Mon, 23 Jun 2014 15:43:41 -0400
97e186
Subject: [PATCH 1/2] rasdaemon: handle failures of snprintf()
97e186
97e186
Florian Weimer found that in bitfield_msg() the return value of
97e186
snprintf() is used to calculate length ignoring that it can return a
97e186
negative number. This patch makes bitfield_msg() to stop writing in such
97e186
case.
97e186
97e186
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1035741
97e186
97e186
Reported-by: Florian Weimer <fweimer@redhat.com>
97e186
Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
97e186
---
97e186
 bitfield.c |    4 ++++
97e186
 1 files changed, 4 insertions(+), 0 deletions(-)
97e186
97e186
diff --git a/bitfield.c b/bitfield.c
97e186
index b2895b4..1690f15 100644
97e186
--- a/bitfield.c
97e186
+++ b/bitfield.c
97e186
@@ -41,6 +41,8 @@ unsigned bitfield_msg(char *buf, size_t len, const char **bitarray,
97e186
 		if (status & (1 <<  (i + bit_offset))) {
97e186
 			if (p != buf) {
97e186
 				n = snprintf(p, len, ", ");
97e186
+				if (n < 0)
97e186
+					break;
97e186
 				len -= n;
97e186
 				p += n;
97e186
 			}
97e186
@@ -48,6 +50,8 @@ unsigned bitfield_msg(char *buf, size_t len, const char **bitarray,
97e186
 				n = snprintf(p, len, "BIT%d", i + bit_offset);
97e186
 			else
97e186
 				n = snprintf(p, len, "%s", bitarray[i]);
97e186
+			if (n < 0)
97e186
+				break;
97e186
 			len -= n;
97e186
 			p += n;
97e186
 		}
97e186
-- 
97e186
1.7.1
97e186