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

Sasha Khapyorsky sashak at voltaire.com
Sat Jun 28 19:12:28 PDT 2008


snprintf() retrns value which can exceed provided buffer size. The check
is needed.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 libibumad/src/umad.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libibumad/src/umad.c b/libibumad/src/umad.c
index 6bcfee6..dcc7275 100644
--- a/libibumad/src/umad.c
+++ b/libibumad/src/umad.c
@@ -134,6 +134,8 @@ get_port(char *ca_name, char *dir, int portnum, umad_port_t *port)
 	port->pkeys = NULL;
 
 	len = snprintf(port_dir, sizeof(port_dir), "%s/%d", dir, portnum);
+	if (len < 0 || len > sizeof(port_dir))
+		goto clean;
 
 	if (sys_read_uint(port_dir, SYS_PORT_LMC, &port->lmc) < 0)
 		goto clean;
-- 
1.5.5.1.178.g1f811




More information about the general mailing list