All of lore.kernel.org
 help / color / mirror / Atom feed
* Possible bug in tools/libxl/libxl.c -- Variable passed by reference not set in one possible case
@ 2014-10-10  1:07 ayush ruia
  2014-10-10  1:28 ` ayush ruia
  0 siblings, 1 reply; 14+ messages in thread
From: ayush ruia @ 2014-10-10  1:07 UTC (permalink / raw)
  To: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 6161 bytes --]

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
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4329>
static int libxl__fill_dom0_memory_info(libxl__gc *gc, uint32_t *target_memkb,
4330
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4330>
                                        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.

http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD

4346
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4346>
    target = libxl__xs_read(gc, t, target_path);
4347
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4347>
    staticmax = libxl__xs_read(gc, t, max_path);
4348
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4348>
    freememslack = libxl__xs_read(gc, t, free_mem_slack_path);
4349
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4349>
    if (target && staticmax && freememslack) {
4350
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4350>
        rc = 0;
4351
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4351>
        goto out;
4352
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4352>
    }
4353
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4353>
4354
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4354>
    if (target) {
4355
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4355>
        *target_memkb = strtoul(target, &endptr, 10);
4356
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4356>
        if (*endptr != '\0') {
4357
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4357>
            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
4358
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4358>
                    "invalid memory target %s from %s\n", target, target_path);
4359
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4359>
            rc = ERROR_FAIL;
4360
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4360>
            goto out;
4361
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4361>
        }
4362
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4362>
    }
4363
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4363>
4364
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4364>
    if (staticmax) {
4365
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4365>
        *max_memkb = strtoul(staticmax, &endptr, 10);
4366
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4366>
        if (*endptr != '\0') {
4367
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4367>
            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
4368
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4368>
                             "invalid memory static-max %s from %s\n",
4369
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4369>
                             staticmax, max_path);
4370
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4370>
            rc = ERROR_FAIL;
4371
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4371>
            goto out;
4372
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4372>
        }
4373
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4373>
    }
4374
<http://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=tools/libxl/libxl.c;h=9c72df27d988d7a4c8f6058708daa16d72be084d;hb=HEAD#l4374>


Regards,
Ayush Ruia.

[-- Attachment #1.2: Type: text/html, Size: 11561 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-10-10 16:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-10  1:07 Possible bug in tools/libxl/libxl.c -- Variable passed by reference not set in one possible case ayush ruia
2014-10-10  1:28 ` ayush ruia
2014-10-10  9:06   ` Wei Liu
2014-10-10  9:17     ` Ian Campbell
2014-10-10  9:24       ` Wei Liu
2014-10-10  9:30         ` Ian Campbell
2014-10-10 10:54           ` Wei Liu
2014-10-10 11:30             ` Ian Campbell
2014-10-10 12:43               ` ayush ruia
2014-10-10 13:58                 ` Wei Liu
2014-10-10 14:47                   ` ayush ruia
2014-10-10 15:27                     ` Ian Campbell
2014-10-10 16:41                       ` ayush ruia
2014-10-10 16:55                         ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.