From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Matthew Daley <mattd@bugfuzz.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 04/13 v2] libxl: don't leak p in libxl__wait_for_backend
Date: Mon, 2 Dec 2013 00:52:51 +0000 [thread overview]
Message-ID: <529BD9E3.8070409@citrix.com> (raw)
In-Reply-To: <CAD3CanffNDfuv-mouzLtEaR1ir4qKtwxqWOY4fEOrqyAp65GTw@mail.gmail.com>
On 02/12/2013 00:46, Matthew Daley wrote:
> On Mon, Dec 2, 2013 at 1:42 PM, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>> On 02/12/2013 00:27, Matthew Daley wrote:
>>> Use libxl__xs_read_checked instead of xs_read. While at it, tidy up the
>>> function as well.
>>>
>>> Coverity-ID: 1055891
>>> Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
>>> ---
>>> v2: Use libxl__xs_read_checked instead of xs_read. Tidy up the function.
>>>
>>> tools/libxl/libxl_device.c | 41 +++++++++++++++++------------------------
>>> tools/libxl/libxl_internal.h | 3 ++-
>>> 2 files changed, 19 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
>>> index d995c83..ba7d100 100644
>>> --- a/tools/libxl/libxl_device.c
>>> +++ b/tools/libxl/libxl_device.c
>>> @@ -1199,37 +1199,30 @@ int libxl__wait_for_device_model_deprecated(libxl__gc *gc,
>>> check_callback, check_callback_userdata);
>>> }
>>>
>>> -int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state)
>>> +int libxl__wait_for_backend(libxl__gc *gc, const char *be_path,
>>> + const char *state)
>>> {
>>> - libxl_ctx *ctx = libxl__gc_owner(gc);
>>> int watchdog = 100;
>>> - unsigned int len;
>>> - char *p;
>>> - char *path = GCSPRINTF("%s/state", be_path);
>>> - int rc = -1;
>>> + const char *p, *path = GCSPRINTF("%s/state", be_path);
>>> + int rc;
>>> +
>>> + while (watchdog-- > 0) {
>>> + rc = libxl__xs_read_checked(gc, XBT_NULL, path, &p);
>> libxl__xs_read_checked() can return 0, with p set to NULL in the case of
>> an ENOENT from xenstore.
>>
>> I think you need a NULL check before strcmp.
>>
>> ~Andrew
>>
>>> + if (rc) return rc;
>>>
>>> - while (watchdog > 0) {
>>> - p = xs_read(ctx->xsh, XBT_NULL, path, &len);
>>> if (p == NULL) {
> ^ That's checked here, isn't it? (The diff has sneakily left it here
> inbetween a bunch of removals)
>
> - Matthew
So it is. That was sneaky.
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
>>> - if (errno == ENOENT) {
>>> - LOG(ERROR, "Backend %s does not exist", be_path);
>>> - } else {
>>> - LOGE(ERROR, "Failed to access backend %s", be_path);
>>> - }
>>> - goto out;
>>> - } else {
>>> - if (!strcmp(p, state)) {
>>> - rc = 0;
>>> - goto out;
>>> - } else {
>>> - usleep(100000);
>>> - watchdog--;
>>> - }
>>> + LOG(ERROR, "Backend %s does not exist", be_path);
>>> + return ERROR_FAIL;
>>> }
>>> +
>>> + if (!strcmp(p, state))
>>> + return 0;
>>> +
>>> + usleep(100000);
>>> }
>>> +
>>> LOG(ERROR, "Backend %s not ready", be_path);
>>> -out:
>>> - return rc;
>>> + return ERROR_FAIL;
>>> }
>>>
>>> /*
>>> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
>>> index a2d8247..1bd23ff 100644
>>> --- a/tools/libxl/libxl_internal.h
>>> +++ b/tools/libxl/libxl_internal.h
>>> @@ -944,7 +944,8 @@ _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
>>> _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
>>> libxl__device *dev);
>>> _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev);
>>> -_hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
>>> +_hidden int libxl__wait_for_backend(libxl__gc *gc, const char *be_path,
>>> + const char *state);
>>> _hidden int libxl__nic_type(libxl__gc *gc, libxl__device *dev,
>>> libxl_nic_type *nictype);
>>>
next prev parent reply other threads:[~2013-12-02 0:52 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-01 10:14 [PATCH 00/13] Coverity fixes for libxl Matthew Daley
2013-12-01 10:14 ` [PATCH 01/13] libxl: fix unsigned less-than-0 comparison in e820_sanitize Matthew Daley
2013-12-13 5:54 ` Matthew Daley
2013-12-13 13:23 ` Andrew Cooper
2013-12-13 17:31 ` Ian Jackson
2013-12-01 10:14 ` [PATCH 02/13] libxl: check for xc_domain_setmaxmem failure in libxl__build_pre Matthew Daley
2013-12-02 11:55 ` Ian Jackson
2013-12-02 12:11 ` [PATCH 02/13 v2] " Matthew Daley
2013-12-13 5:53 ` Matthew Daley
2013-12-13 10:17 ` Dario Faggioli
2013-12-13 17:23 ` Ian Jackson
2013-12-01 10:14 ` [PATCH 03/13] libxl: correct file open success check in libxl__device_pci_reset Matthew Daley
2013-12-02 11:57 ` Ian Jackson
2013-12-01 10:14 ` [PATCH 04/13] libxl: don't leak p in libxl__wait_for_backend Matthew Daley
2013-12-01 11:53 ` Andrew Cooper
2013-12-01 23:17 ` Matthew Daley
2013-12-02 0:27 ` [PATCH 04/13 v2] " Matthew Daley
2013-12-02 0:42 ` Andrew Cooper
2013-12-02 0:46 ` Matthew Daley
2013-12-02 0:52 ` Andrew Cooper [this message]
2013-12-02 12:00 ` Ian Jackson
2014-01-09 14:51 ` Ian Jackson
2013-12-01 10:14 ` [PATCH 05/13] libxl: remove unsigned less-than-0 comparison Matthew Daley
2013-12-02 12:05 ` Ian Jackson
2013-12-01 10:15 ` [PATCH 06/13] libxl: actually abort if initializing a ctx's lock fails Matthew Daley
2013-12-02 12:05 ` Ian Jackson
2013-12-01 10:15 ` [PATCH 07/13] libxl: don't leak output vcpu info on error in libxl_list_vcpu Matthew Daley
2013-12-02 12:05 ` Ian Jackson
2013-12-01 10:15 ` [PATCH 08/13] libxl: don't leak ptr in libxl_list_vm error case Matthew Daley
2013-12-01 12:20 ` Andrew Cooper
2013-12-02 0:30 ` Matthew Daley
2013-12-02 0:37 ` [PATCH 08/13 v2] " Matthew Daley
2013-12-02 0:39 ` Andrew Cooper
2013-12-02 2:58 ` [PATCH 08/13 v3] " Matthew Daley
2013-12-02 10:35 ` Andrew Cooper
2013-12-02 10:47 ` Matthew Daley
2013-12-02 10:50 ` Ian Campbell
2013-12-02 11:05 ` [PATCH 08/13 v4] " Matthew Daley
2013-12-02 11:10 ` Andrew Cooper
2013-12-02 12:08 ` Ian Jackson
2013-12-02 12:19 ` Matthew Daley
2013-12-02 15:03 ` Ian Jackson
2013-12-03 1:29 ` [PATCH 08/13 v5] " Matthew Daley
2013-12-03 10:21 ` Ian Campbell
2013-12-03 10:30 ` Andrew Cooper
2013-12-13 16:52 ` [PATCH 08/13 v5] libxl: don't leak ptr in libxl_list_vm error case [and 1 more messages] Ian Jackson
2013-12-13 17:05 ` Andrew Cooper
2013-12-13 17:21 ` Ian Jackson
2013-12-13 23:22 ` Matthew Daley
2013-12-13 23:26 ` Matthew Daley
2013-12-16 11:57 ` Ian Jackson
2013-12-14 1:15 ` [PATCH] xl: check for libxl_list_vm failure in print_uptime Matthew Daley
2013-12-16 11:57 ` Ian Jackson
2013-12-16 11:58 ` Ian Jackson
2013-12-13 5:52 ` [PATCH 08/13 v5] libxl: don't leak ptr in libxl_list_vm error case Matthew Daley
2013-12-01 10:15 ` [PATCH 09/13] libxl: don't leak pcidevs in libxl_pcidev_assignable Matthew Daley
2013-12-02 12:15 ` Ian Jackson
2013-12-01 10:15 ` [PATCH 10/13] libxl: don't try to fclose file twice on error in libxl_userdata_store Matthew Daley
2013-12-02 12:14 ` Ian Jackson
2013-12-02 12:24 ` Matthew Daley
2013-12-02 15:04 ` Ian Jackson
2013-12-02 23:56 ` [PATCH 10/13 v2] " Matthew Daley
2013-12-03 0:00 ` [PATCH 10/13 v3] " Matthew Daley
2013-12-03 17:28 ` Ian Jackson
2013-12-01 10:15 ` [PATCH 11/13] libxl: use pipe instead of temporary file for VNC viewer --autopass Matthew Daley
2013-12-02 12:22 ` Ian Jackson
2013-12-02 12:34 ` Matthew Daley
2013-12-01 10:15 ` [PATCH 12/13] libxl: don't leak buf in libxl_xen_console_read_start error handling Matthew Daley
2013-12-02 12:25 ` Ian Jackson
2013-12-03 1:01 ` [PATCH 12/13 v2] " Matthew Daley
2013-12-03 17:26 ` Ian Jackson
2013-12-01 10:15 ` [PATCH 13/13] libxl: replace for loop with more idiomatic do-while loop Matthew Daley
2013-12-02 12:26 ` Ian Jackson
2013-12-02 12:46 ` Matthew Daley
2013-12-01 12:22 ` [PATCH 00/13] Coverity fixes for libxl Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=529BD9E3.8070409@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=mattd@bugfuzz.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).