[openib-general] [PATCH] diags/saquery: fix node_desc.description as string usages

Sasha Khapyorsky sashak at voltaire.com
Sat Oct 28 13:25:32 PDT 2006


On 22:12 Sat 28 Oct     , Muli Ben-Yehuda wrote:
> On Sat, Oct 28, 2006 at 10:04:25PM +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 strcmp() or printf() leads to segmentation faults.
> > This patch fixes such usages.
> > 
> > Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
> > ---
> >  diags/src/saquery.c |   22 ++++++++++++++++------
> >  1 files changed, 16 insertions(+), 6 deletions(-)
> > 
> > diff --git a/diags/src/saquery.c b/diags/src/saquery.c
> > index 5b4a85e..f5b23fd 100644
> > --- a/diags/src/saquery.c
> > +++ b/diags/src/saquery.c
> > @@ -90,17 +90,21 @@ static void
> >  print_node_desc(ib_node_record_t *node_record)
> >  {
> >  	ib_node_info_t *p_ni = &(node_record->node_info);
> > +	ib_node_desc_t *p_nd = &(node_record->node_desc);
> >  	if (p_ni->node_type == IB_NODE_TYPE_CA)
> >  	{
> > +		char desc[sizeof(p_nd->description) + 1];
> > +		memcpy(desc, p_nd->description, sizeof(p_nd->description));
> > +		desc[sizeof(desc) - 1] = '\0';
> 
> No need for the -1 here - desc is (sizeof(p_nd->description) + 1), so
> the terminating NULL should be at index sizeof().

At index sizeof(p_nd->description) - yes, but not at sizeof(desc) as it
is used here (this one has extra byte).

Sasha




More information about the general mailing list