[openib-general] [PATCH][kdapl] Small changes in dapl_hca_all oc/dapl_hca_free functions

Itamar Rabenstein itamar at mellanox.co.il
Mon Jun 20 10:00:14 PDT 2005


Hi Tom,
I was just copied to original code from dapl_os_strdup() to
dapl_hca_alloc().
so if it is a problem is it was there in the code before my patch.
But why do you think we need strncpy and not strcpy ?
name param is null terminated string.

 Itamar

> -----Original Message-----
> From: Tom Duffy [mailto:tomduffy at gmail.com]
> Sent: Monday, June 20, 2005 6:00 PM
> To: Itamar Rabenstein
> Cc: James.Lentini at netapp.com; openib-general at openib.org
> Subject: Re: [openib-general] [PATCH][kdapl] Small changes in
> dapl_hca_alloc/dapl_hca_free functions
> 
> 
> On 6/20/05, Itamar Rabenstein <itamar at mellanox.co.il> wrote:
> > Small changes in dapl_hca_alloc/dapl_hca_free function
> > 
> > Signed-off-by: Itamar Rabenstein <itamar at mellanox.co.il>
> > 
> > diff -Nurp -X dontdiff dat-provider_hash/dapl_hca_util.c 
> dat-provider/dapl_hca_util.c
> > --- dat-provider_hash/dapl_hca_util.c   Sun Jun 19 16:12:55 2005
> > +++ dat-provider/dapl_hca_util.c        Sun Jun 19 16:30:07 2005
> > @@ -54,23 +54,18 @@
> >  struct dapl_hca *dapl_hca_alloc(char *name, struct 
> ib_device *device, u8 port)
> >  {
> >         struct dapl_hca *hca;
> > -
> > -       hca = kmalloc(sizeof *hca, GFP_ATOMIC);
> > +       int malloc_size = sizeof *hca + strlen(name) + 1;
> > +
> > +       hca = kmalloc(malloc_size, GFP_ATOMIC);
> >         if (hca) {
> > -               memset(hca, 0, sizeof *hca);
> > -
> > +               memset(hca, 0, malloc_size);
> >                 spin_lock_init(&hca->lock);
> >                 INIT_LIST_HEAD(&hca->ia_list);
> > -
> > -               hca->name = dapl_os_strdup(name);
> > +               hca->name = (char *)hca + sizeof *hca;
> > +               strcpy(hca->name, name);
> 
> Shouldn't you use strncpy() and bound it?
> 
> -tduffy
> 



More information about the general mailing list