[openib-general] [PATCH] osmtest: fix node_desc.description as string usages

Sasha Khapyorsky sashak at voltaire.com
Sat Oct 28 13:03:07 PDT 2006


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.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/osmtest/osmtest.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/osm/osmtest/osmtest.c b/osm/osmtest/osmtest.c
index b4d9498..6444b9d 100644
--- a/osm/osmtest/osmtest.c
+++ b/osm/osmtest/osmtest.c
@@ -1984,11 +1984,15 @@ osmtest_write_node_info( IN osmtest_t *
                          IN FILE * fh,
                          IN const ib_node_record_t * const p_rec )
 {
+  char desc[IB_NODE_DESCRIPTION_SIZE];
   int result;
   cl_status_t status = IB_SUCCESS;
 
   OSM_LOG_ENTER( &p_osmt->log, osmtest_write_node_info );
 
+  memcpy(desc, p_rec->node_desc.description, IB_NODE_DESCRIPTION_SIZE);
+  desc[IB_NODE_DESCRIPTION_SIZE] = '\0';
+
   result = fprintf( fh,
                     "DEFINE_NODE\n"
                     "lid                     0x%X\n"
@@ -2021,7 +2025,7 @@ osmtest_write_node_info( IN osmtest_t *
                     ib_node_info_get_local_port_num( &p_rec->node_info ),
                     cl_ntoh32( ib_node_info_get_vendor_id
                                ( &p_rec->node_info ) ),
-                    p_rec->node_desc.description );
+                    desc );
 
   if( result < 0 )
   {
-- 
1.4.3.2.g4bf7





More information about the general mailing list