[ofa-general] [PATCH] opensm: fix snprintf() usage

Sasha Khapyorsky sashak at voltaire.com
Sat Jun 28 18:48:37 PDT 2008


snprintf() returns number of bytes which would be printed ignoring
possible lack of the space. So this can exceed provided buffer size.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/opensm/osm_subnet.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index cd3b4de..02d7426 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -472,7 +472,11 @@ static void log_config_value(char *name, const char *fmt, ...)
 	unsigned n;
 	va_start(args, fmt);
 	n = snprintf(buf, sizeof(buf), " Loading Cached Option:%s = ", name);
+	if (n > sizeof(buf))
+		n = sizeof(buf);
 	n += vsnprintf(buf + n, sizeof(buf) - n, fmt, args);
+	if (n > sizeof(buf))
+		n = sizeof(buf);
 	snprintf(buf + n, sizeof(buf) - n, "\n");
 	va_end(args);
 	printf(buf);
-- 
1.5.5.1.178.g1f811




More information about the general mailing list