[openib-general] [PATCH] opensm: osm_ucast_mgr.c: fix node_desc.description as string usages [was: [PATCH 2/5] opensm: ucast_mgr dumper unification]

Sasha Khapyorsky sashak at voltaire.com
Sat Oct 28 13:17:50 PDT 2006


On 22:35 Thu 19 Oct     , Sasha Khapyorsky wrote:
> This unifies ucsat_mgr dumper. Main goal is to provide infrastructure
> for different dump file generation using the same routines.
> 
> Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
> ---
>  osm/opensm/osm_ucast_mgr.c |  104 +++++++++++++++++++++++---------------------
>  1 files changed, 55 insertions(+), 49 deletions(-)
> 

And there is incremental patch already:


node_desc.description buffer is received from the network and should
not be NULL-terminated. In such cases using it as regular string in
functions like printf() leads to segmentation faults. This patch fixes
such usages. This was in new lft dumper too.

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

diff --git a/osm/opensm/osm_ucast_mgr.c b/osm/opensm/osm_ucast_mgr.c
index c0c1738..d008d91 100644
--- a/osm/opensm/osm_ucast_mgr.c
+++ b/osm/opensm/osm_ucast_mgr.c
@@ -355,6 +355,7 @@ ucast_mgr_dump_lid_matrix(cl_map_item_t
 static void
 ucast_mgr_dump_lfts(cl_map_item_t *p_map_item, void *cxt)
 {
+	char desc[IB_NODE_DESCRIPTION_SIZE + 1];
 	osm_switch_t* p_sw = (osm_switch_t *)p_map_item;
 	osm_ucast_mgr_t* p_mgr = ((struct ucast_mgr_dump_context *)cxt)->p_mgr;
 	FILE *file = ((struct ucast_mgr_dump_context *)cxt)->file;
@@ -364,11 +365,12 @@ ucast_mgr_dump_lfts(cl_map_item_t *p_map
 	uint16_t lid;
 	uint8_t port;
 
+	memcpy(desc, p_node->node_desc.description, IB_NODE_DESCRIPTION_SIZE);
+	desc[IB_NODE_DESCRIPTION_SIZE] = '\0';
 	fprintf(file, "Unicast lids [0x0-0x%x] of switch Lid %u guid 0x%016"
 		PRIx64 " (\'%s\'):\n",
 		max_lid, osm_node_get_base_lid(p_node, 0),
-		cl_ntoh64(osm_node_get_node_guid(p_node)),
-		p_node->node_desc.description);
+		cl_ntoh64(osm_node_get_node_guid(p_node)), desc);
 	for (lid = 0; lid <= max_lid; lid++) {
 		osm_port_t *p_port;
 		port = osm_switch_get_port_by_lid(p_sw, lid);
@@ -381,10 +383,12 @@ ucast_mgr_dump_lfts(cl_map_item_t *p_map
 		p_port = cl_ptr_vector_get(&p_mgr->p_subn->port_lid_tbl, lid);
 		if (p_port) {
 			p_node = osm_port_get_parent_node(p_port);
+			memcpy(desc, p_node->node_desc.description,
+			       IB_NODE_DESCRIPTION_SIZE);
+			desc[IB_NODE_DESCRIPTION_SIZE] = '\0';
 			fprintf(file, "%s portguid 0x016%" PRIx64 ": \'%s\'",
 				ib_get_node_type_str(osm_node_get_type(p_node)),
-				cl_ntoh64(osm_port_get_guid(p_port)),
-				p_node->node_desc.description);
+				cl_ntoh64(osm_port_get_guid(p_port)), desc);
 		}
 		else
 			fprintf(file, "unknown node and type");
-- 
1.4.3.2.g4bf7





More information about the general mailing list