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

Sasha Khapyorsky sashak at voltaire.com
Sat Oct 28 13:21:14 PDT 2006


On 22:09 Sat 28 Oct     , Muli Ben-Yehuda wrote:
> 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.

No, but I meant IB_NODE_DESCRIPTION_SIZE + 1 above. Thanks for catching.

Sasha




More information about the general mailing list