[openib-general] [PATCH] opensm: misc fixes in lft dump file parser

Sasha Khapyorsky sashak at voltaire.com
Tue Oct 17 11:28:56 PDT 2006


There are misc small fixes for lft dump parser:
- merge ERROR and SYS logging in single osm_log() call
- more strict strtoul() results checking
- fix potential bugs with invalid dump files
- break too long lines

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/opensm/osm_ucast_file.c |   69 +++++++++++++++++++++++--------------------
 1 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/osm/opensm/osm_ucast_file.c b/osm/opensm/osm_ucast_file.c
index da39d1a..446c243 100644
--- a/osm/opensm/osm_ucast_file.c
+++ b/osm/opensm/osm_ucast_file.c
@@ -132,21 +132,19 @@ static int do_ucast_file_load(void *cont
 
 	file_name = p_osm->subn.opt.ucast_dump_file;
 	if (!file_name) {
-		osm_log(&p_osm->log, OSM_LOG_SYS,
-			"ucast dump file name is not defined; using default routing algorithm\n");
-		osm_log(&p_osm->log, OSM_LOG_ERROR,
+		osm_log(&p_osm->log, OSM_LOG_ERROR|OSM_LOG_SYS,
 			"do_ucast_file_load: ERR 6301: "
-			"ucast dump file name is not defined; using default routing algorithm\n");
+			"ucast dump file name is not defined; "
+			"using default routing algorithm\n");
 		return -1;
 	}
 
 	file = fopen(file_name, "r");
 	if (!file) {
-		osm_log(&p_osm->log, OSM_LOG_SYS,
-			"Cannot open ucast dump file \'%s\'; using default routing algorithm\n", file_name);
-		osm_log(&p_osm->log, OSM_LOG_ERROR,
+		osm_log(&p_osm->log, OSM_LOG_ERROR|OSM_LOG_SYS,
 			"do_ucast_file_load: ERR 6302: "
-			"cannot open ucast dump file \'%s\'; using default routing algorithm\n", file_name);
+			"cannot open ucast dump file \'%s\'; "
+			"using default routing algorithm\n", file_name);
 		return -1;
 	}
 
@@ -167,25 +165,25 @@ static int do_ucast_file_load(void *cont
 			continue;
 
 		if (!strncmp(p, "Multicast mlids", 15)) {
-			osm_log(&p_osm->log, OSM_LOG_SYS,
-				"Multicast dump file detected; "
-				"skipping parsing. Using default routing algorithm\n");
-			osm_log(&p_osm->log, OSM_LOG_ERROR,
+			osm_log(&p_osm->log, OSM_LOG_ERROR|OSM_LOG_SYS,
 				"do_ucast_file_load: ERR 6303: "
 				"Multicast dump file detected; "
-				"skipping parsing. Using default routing algorithm\n");
+				"skipping parsing. Using default "
+				"routing algorithm\n");
 		} else if (!strncmp(p, "Unicast lids", 12)) {
 			q = strstr(p, " guid 0x");
 			if (!q) {
-				osm_log(&p_osm->log, OSM_LOG_ERROR, "PARSE ERROR: %s:%u: "
+				osm_log(&p_osm->log, OSM_LOG_ERROR,
+					"PARSE ERROR: %s:%u: "
 					"cannot parse switch definition\n",
 					file_name, lineno);
 				return -1;
 			}
-			p = q + 6;
+			p = q + 8;
 			sw_guid = strtoull(p, &q, 16);
-			if (q && !isspace(*q)) {
-				osm_log(&p_osm->log, OSM_LOG_ERROR, "PARSE ERROR: %s:%u: "
+			if (q == p || !isspace(*q)) {
+				osm_log(&p_osm->log, OSM_LOG_ERROR,
+					"PARSE ERROR: %s:%u: "
 					"cannot parse switch guid: \'%s\'\n",
 					file_name, lineno, p);
 				return -1;
@@ -204,39 +202,46 @@ static int do_ucast_file_load(void *cont
 				continue;
 			}
 		} else if (p_sw && !strncmp(p, "0x", 2)) {
+			p += 2;
 			lid = (uint16_t)strtoul(p, &q, 16);
-			if (q && !isspace(*q)) {
-				osm_log(&p_osm->log, OSM_LOG_ERROR, "PARSE ERROR: %s:%u: "
-					"cannot parse lid: \'%s\'\n", file_name, lineno, p);
+			if (q == p || !isspace(*q)) {
+				osm_log(&p_osm->log, OSM_LOG_ERROR,
+					"PARSE ERROR: %s:%u: "
+					"cannot parse lid: \'%s\'\n",
+					file_name, lineno, p);
 				return -1;
 			}
 			p = q;
 			while (isspace(*p))
 				p++;
 			port_num = (uint8_t)strtoul(p, &q, 10);
-			if (q && !isspace(*q)) {
-				osm_log(&p_osm->log, OSM_LOG_ERROR, "PARSE ERROR: %s:%u: "
-					"cannot parse port: \'%s\'\n", file_name, lineno, p);
+			if (q == p || !isspace(*q)) {
+				osm_log(&p_osm->log, OSM_LOG_ERROR,
+					"PARSE ERROR: %s:%u: "
+					"cannot parse port: \'%s\'\n",
+					file_name, lineno, p);
 				return -1;
 			}
 			p = q;
 			/* additionally try to exract guid */
 			q = strstr(p, " portguid 0x");
 			if (!q) {
-				osm_log(&p_osm->log, OSM_LOG_VERBOSE, "PARSE WARNING: %s:%u: "
+				osm_log(&p_osm->log, OSM_LOG_VERBOSE,
+					"PARSE WARNING: %s:%u: "
 					"cannot find port guid "
-					"(maybe broken dump): \'%s\'\n", file_name, lineno, p);
+					"(maybe broken dump): \'%s\'\n",
+					file_name, lineno, p);
 				port_guid = 0;
 			}
-			else
-			{
-				p = q + 10;
+			else {
+				p = q + 12;
 				port_guid = strtoull(p, &q, 16);
-				if (!q && !isspace(*q) && *q != ':') {
-					osm_log(&p_osm->log, OSM_LOG_VERBOSE, "PARSE WARNING: %s:%u: "
+				if (q == p || (!isspace(*q) && *q != ':')) {
+					osm_log(&p_osm->log, OSM_LOG_VERBOSE,
+						"PARSE WARNING: %s:%u: "
 						"cannot parse port guid "
-						"(maybe broken dump): "
-						"\'%s\'\n", file_name, lineno, p);
+						"(maybe broken dump): \'%s\'\n",
+						file_name, lineno, p);
 					port_guid = 0;
 				}
 			}
-- 
1.4.2.3





More information about the general mailing list