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

Muli Ben-Yehuda muli at il.ibm.com
Sat Oct 28 13:09:34 PDT 2006


On Sat, Oct 28, 2006 at 10:03:07PM +0200, Sasha Khapyorsky wrote:
> 
> 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';

You mean IB_NODE_DESCRIPTION_SIZE - 1 here.

Cheers,
Muli




More information about the general mailing list