[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] Possible bug in tools/libxl/libxl.c -- Variable passed by reference not set in one possible case


  • To: xen-devel@xxxxxxxxxxxxx
  • From: ayush ruia <ayushruia@xxxxxxxxx>
  • Date: Thu, 9 Oct 2014 20:28:53 -0500
  • Delivery-date: Fri, 10 Oct 2014 06:40:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

What I am trying to say is that shouldn't the code block highlighted in yellow should come before the block marked in green. Then it would update the value of *target_memkb and *max_memkb in all possible situations.

4346 ÂÂÂÂtargetÂ=Âlibxl__xs_read(gc,Ât,Âtarget_path);
4347 ÂÂÂÂstaticmaxÂ=Âlibxl__xs_read(gc,Ât,Âmax_path);
4348 ÂÂÂÂfreememslackÂ=Âlibxl__xs_read(gc,Ât,Âfree_mem_slack_path);



4349 ÂÂÂÂifÂ(targetÂ&&ÂstaticmaxÂ&&Âfreememslack)Â{
4350 ÂÂÂÂÂÂÂÂrcÂ=Â0;
4351 ÂÂÂÂÂÂÂÂgotoÂout;
4352 ÂÂÂÂ}
4354 ÂÂÂÂifÂ(target)Â{
4355 ÂÂÂÂÂÂÂÂ*target_memkbÂ=Âstrtoul(target,Â&endptr,Â10);
4356 ÂÂÂÂÂÂÂÂifÂ(*endptrÂ!=Â'\0')Â{
4357 ÂÂÂÂÂÂÂÂÂÂÂÂLIBXL__LOG_ERRNO(ctx,ÂLIBXL__LOG_ERROR,
4358 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"invalidÂmemoryÂtargetÂ%sÂfromÂ%s\n",Âtarget,Âtarget_path);
4359 ÂÂÂÂÂÂÂÂÂÂÂÂrcÂ=ÂERROR_FAIL;
4360 ÂÂÂÂÂÂÂÂÂÂÂÂgotoÂout;
4361 ÂÂÂÂÂÂÂÂ}
4362 ÂÂÂÂ}
4364 ÂÂÂÂifÂ(staticmax)Â{
4365 ÂÂÂÂÂÂÂÂ*max_memkbÂ=Âstrtoul(staticmax,Â&endptr,Â10);
4366 ÂÂÂÂÂÂÂÂifÂ(*endptrÂ!=Â'\0')Â{
4367 ÂÂÂÂÂÂÂÂÂÂÂÂLIBXL__LOG_ERRNO(ctx,ÂLIBXL__LOG_ERROR,
4368 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"invalidÂmemoryÂstatic-maxÂ%sÂfromÂ%s\n",
4369 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstaticmax,Âmax_path);
4370 ÂÂÂÂÂÂÂÂÂÂÂÂrcÂ=ÂERROR_FAIL;
4371 ÂÂÂÂÂÂÂÂÂÂÂÂgotoÂout;
4372 ÂÂÂÂÂÂÂÂ}
4373 ÂÂÂÂ}

Regards,
Ayush Ruia.

On Thu, Oct 9, 2014 at 8:07 PM, ayush ruia <ayushruia@xxxxxxxxx> wrote:
Hi,
In the functionÂlibxl__fill_dom0_memory_info in the file libxl.c, here we see that the function is called as follows:

4329 staticÂintÂlibxl__fill_dom0_memory_info(libxl__gcÂ*gc,Âuint32_tÂ*target_memkb,
4330 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂuint32_tÂ*max_memkb)


Here, we are passed the pointers to the variables *max_memkb and *target_memkb. In the code below we see that we first read the string value of target, staticmax, and freememslack from the files listed in the path in the function. However, if the values are set, then we do not update the value of the pointers passed via reference in the function call. Only if the three variables are not set, then do we update the values of the variable passed through reference. Otherwise these values are not updated and the functions exits. This might be a bug, or it may be intentional. I do not understand why are we passing the variables via reference in the function if it is not even set in the function.Â


4346 ÂÂÂÂtargetÂ=Âlibxl__xs_read(gc,Ât,Âtarget_path);
4347 ÂÂÂÂstaticmaxÂ=Âlibxl__xs_read(gc,Ât,Âmax_path);
4348 ÂÂÂÂfreememslackÂ=Âlibxl__xs_read(gc,Ât,Âfree_mem_slack_path);
4349 ÂÂÂÂifÂ(targetÂ&&ÂstaticmaxÂ&&Âfreememslack)Â{
4350 ÂÂÂÂÂÂÂÂrcÂ=Â0;
4351 ÂÂÂÂÂÂÂÂgotoÂout;
4352 ÂÂÂÂ}
4354 ÂÂÂÂifÂ(target)Â{
4355 ÂÂÂÂÂÂÂÂ*target_memkbÂ=Âstrtoul(target,Â&endptr,Â10);
4356 ÂÂÂÂÂÂÂÂifÂ(*endptrÂ!=Â'\0')Â{
4357 ÂÂÂÂÂÂÂÂÂÂÂÂLIBXL__LOG_ERRNO(ctx,ÂLIBXL__LOG_ERROR,
4358 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"invalidÂmemoryÂtargetÂ%sÂfromÂ%s\n",Âtarget,Âtarget_path);
4359 ÂÂÂÂÂÂÂÂÂÂÂÂrcÂ=ÂERROR_FAIL;
4360 ÂÂÂÂÂÂÂÂÂÂÂÂgotoÂout;
4361 ÂÂÂÂÂÂÂÂ}
4362 ÂÂÂÂ}
4364 ÂÂÂÂifÂ(staticmax)Â{
4365 ÂÂÂÂÂÂÂÂ*max_memkbÂ=Âstrtoul(staticmax,Â&endptr,Â10);
4366 ÂÂÂÂÂÂÂÂifÂ(*endptrÂ!=Â'\0')Â{
4367 ÂÂÂÂÂÂÂÂÂÂÂÂLIBXL__LOG_ERRNO(ctx,ÂLIBXL__LOG_ERROR,
4368 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"invalidÂmemoryÂstatic-maxÂ%sÂfromÂ%s\n",
4369 ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂstaticmax,Âmax_path);
4370 ÂÂÂÂÂÂÂÂÂÂÂÂrcÂ=ÂERROR_FAIL;
4371 ÂÂÂÂÂÂÂÂÂÂÂÂgotoÂout;
4372 ÂÂÂÂÂÂÂÂ}
4373 ÂÂÂÂ}


Regards,
Ayush Ruia.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.