On Fri, Jun 19, 2009 at 12:39:35AM +0530, Balbir Singh wrote:
> * Dhaval Giani <[email protected]> [2009-06-19 00:09:42]:
> 
> > On Thu, Jun 18, 2009 at 10:52:17PM +0530, Balbir Singh wrote:
> > > * Ivana Varekova <[email protected]> [2009-06-18 07:50:30]:
> > > 
> > > > This patche add a test to cgroup_init function, which prevent to add
> > > > multiple records for the same controller (this is a problem eg. in
> > > > cgroup_get_cgroup function - which looks to mount table and add all
> > > > relevant controllers using cgroup_add_controller function and when the
> > > > function calls cgroup_add_cgroup function twice on the same controller,
> > > > it returns error so the result is cgroup_get_cgroup failed).
> > > > 
> > > > Signed-off-by: Ivana Varekova <[email protected]>
> > > > ---
> > > > 
> > > >  src/api.c |   18 ++++++++++++++++++
> > > >  1 files changed, 18 insertions(+), 0 deletions(-)
> > > > 
> > > > diff --git a/src/api.c b/src/api.c
> > > > index 4f88d20..097060c 100644
> > > > --- a/src/api.c
> > > > +++ b/src/api.c
> > > > @@ -570,6 +570,8 @@ int cgroup_init()
> > > >         char subsys_name[FILENAME_MAX];
> > > >         int hierarchy, num_cgroups, enabled;
> > > >         int i=0;
> > > > +       int j;
> > > > +       int duplicate = 0;
> > > >         char *mntopt = NULL;
> > > >         int err;
> > > >         char *buf = NULL;
> > > > @@ -648,6 +650,22 @@ int cgroup_init()
> > > >                                 continue;
> > > > 
> > > >                         cgroup_dbg("matched %s:%s\n", mntopt, 
> > > > controllers[i]);
> > > > +
> > > > +                       /* do not have duplicates in mount table */
> > > > +                       duplicate = 0;
> > > > +                       for  (j = 0; j < found_mnt; j++) {
> > > > +                               if (strncmp(mntopt, 
> > > > cg_mount_table[j].name, FILENAME_MAX)
> > > 
> > > The length to strncmp() should be the shortest length, in our case
> > > it should strlen(cg_mount_table[j].name). We can't rely on maximum
> > > length or length of input.
> > > 
> > 
> > Are you sure it should be the shortest length? So what will happen when
> > mntopt says cpu and cg_mount_table[j].name says cpuset?
> 
> Good point, lets consider
> 
> 1. mntopt is cpu and cg_mount_table[j].name is cpuset, strlen is 6 so
>    strncmp will fail as expected
> 2. mntopt is cpuset and cg_mount_table[j].name is cpu, strlen is 3 and
>    strcmp will succeed
> 
> So the shortest length still holds true, looks like we need to set the
> length to strlen(mntopt).
> 

Sorry, I a being a bit dense. But how does it hold true?

> I think the correct answer is to use
> strlen(cg_mount_table[j].name) + 1
> 

consider that cg_mount_table[j].name is not NULL terminated. Then?
So is it not right to use the size of cg_mount_table[j].name which is
FILENAME_MAX here as opposed to what is suggested by you?

thanks,
-- 
regards,
Dhaval

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to