* [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()
@ 2014-09-24 11:39 Andrew Cooper
2014-09-24 12:39 ` Wei Liu
2014-09-24 14:24 ` Ian Campbell
0 siblings, 2 replies; 6+ messages in thread
From: Andrew Cooper @ 2014-09-24 11:39 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Ian Campbell, Wei Liu
Coverity-ID: 1240235
* filename may be NULL, at which point calling unlink() would be unwise.
Coverity-ID: 1240237
* Initalise rc to 0 to avoid returning stack junk in the success case.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
tools/libxl/libxl_dom.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index bd21841..11c2683 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -2097,7 +2097,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
const char *userdata_userid)
{
GC_INIT(ctx);
- int rc;
+ int rc = 0;
libxl__domain_userdata_lock *lock;
const char *filename;
@@ -2110,7 +2110,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
}
filename = libxl__userdata_path(gc, domid, userdata_userid, "d");
- if (unlink(filename)) rc = ERROR_FAIL;
+ if (!filename || unlink(filename)) rc = ERROR_FAIL;
libxl__unlock_domain_userdata(lock);
out:
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()
2014-09-24 11:39 [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink() Andrew Cooper
@ 2014-09-24 12:39 ` Wei Liu
2014-09-24 14:24 ` Ian Campbell
1 sibling, 0 replies; 6+ messages in thread
From: Wei Liu @ 2014-09-24 12:39 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Wei Liu, Ian Jackson, Ian Campbell, Xen-devel
On Wed, Sep 24, 2014 at 12:39:45PM +0100, Andrew Cooper wrote:
> Coverity-ID: 1240235
> * filename may be NULL, at which point calling unlink() would be unwise.
>
> Coverity-ID: 1240237
> * Initalise rc to 0 to avoid returning stack junk in the success case.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Thanks for fixing this up.
Wei.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()
2014-09-24 11:39 [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink() Andrew Cooper
2014-09-24 12:39 ` Wei Liu
@ 2014-09-24 14:24 ` Ian Campbell
2014-09-24 14:25 ` Andrew Cooper
2014-09-24 14:31 ` Ian Jackson
1 sibling, 2 replies; 6+ messages in thread
From: Ian Campbell @ 2014-09-24 14:24 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Wei Liu, Ian Jackson, Xen-devel
On Wed, 2014-09-24 at 12:39 +0100, Andrew Cooper wrote:
> Coverity-ID: 1240235
> * filename may be NULL, at which point calling unlink() would be unwise.
Oops!
> Coverity-ID: 1240237
> * Initalise rc to 0 to avoid returning stack junk in the success case.
Doing this right before the out: label is helpful since it helps the
compiler catch failure paths which forget to set rc.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> ---
> tools/libxl/libxl_dom.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
> index bd21841..11c2683 100644
> --- a/tools/libxl/libxl_dom.c
> +++ b/tools/libxl/libxl_dom.c
> @@ -2097,7 +2097,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
> const char *userdata_userid)
> {
> GC_INIT(ctx);
> - int rc;
> + int rc = 0;
>
> libxl__domain_userdata_lock *lock;
> const char *filename;
> @@ -2110,7 +2110,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
> }
>
> filename = libxl__userdata_path(gc, domid, userdata_userid, "d");
> - if (unlink(filename)) rc = ERROR_FAIL;
> + if (!filename || unlink(filename)) rc = ERROR_FAIL;
>
> libxl__unlock_domain_userdata(lock);
> out:
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()
2014-09-24 14:24 ` Ian Campbell
@ 2014-09-24 14:25 ` Andrew Cooper
2014-09-24 14:30 ` Ian Jackson
2014-09-24 14:31 ` Ian Jackson
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Cooper @ 2014-09-24 14:25 UTC (permalink / raw)
To: Ian Campbell; +Cc: Wei Liu, Ian Jackson, Xen-devel
On 24/09/14 15:24, Ian Campbell wrote:
> On Wed, 2014-09-24 at 12:39 +0100, Andrew Cooper wrote:
>> Coverity-ID: 1240235
>> * filename may be NULL, at which point calling unlink() would be unwise.
> Oops!
>
>> Coverity-ID: 1240237
>> * Initalise rc to 0 to avoid returning stack junk in the success case.
> Doing this right before the out: label is helpful since it helps the
> compiler catch failure paths which forget to set rc.
Good point - v2 incoming.
~Andrew
>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> CC: Ian Campbell <Ian.Campbell@citrix.com>
>> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
>> CC: Wei Liu <wei.liu2@citrix.com>
>> ---
>> tools/libxl/libxl_dom.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
>> index bd21841..11c2683 100644
>> --- a/tools/libxl/libxl_dom.c
>> +++ b/tools/libxl/libxl_dom.c
>> @@ -2097,7 +2097,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
>> const char *userdata_userid)
>> {
>> GC_INIT(ctx);
>> - int rc;
>> + int rc = 0;
>>
>> libxl__domain_userdata_lock *lock;
>> const char *filename;
>> @@ -2110,7 +2110,7 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t domid,
>> }
>>
>> filename = libxl__userdata_path(gc, domid, userdata_userid, "d");
>> - if (unlink(filename)) rc = ERROR_FAIL;
>> + if (!filename || unlink(filename)) rc = ERROR_FAIL;
>>
>> libxl__unlock_domain_userdata(lock);
>> out:
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()
2014-09-24 14:24 ` Ian Campbell
2014-09-24 14:25 ` Andrew Cooper
@ 2014-09-24 14:31 ` Ian Jackson
1 sibling, 0 replies; 6+ messages in thread
From: Ian Jackson @ 2014-09-24 14:31 UTC (permalink / raw)
To: Ian Campbell; +Cc: Andrew Cooper, Wei Liu, Xen-devel
Ian Campbell writes ("Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()"):
> Doing this right before the out: label is helpful since it helps the
> compiler catch failure paths which forget to set rc.
Do we know why the compiler didn't spot that on this occasion ?
Ian.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-09-24 14:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-24 11:39 [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink() Andrew Cooper
2014-09-24 12:39 ` Wei Liu
2014-09-24 14:24 ` Ian Campbell
2014-09-24 14:25 ` Andrew Cooper
2014-09-24 14:30 ` Ian Jackson
2014-09-24 14:31 ` Ian Jackson
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.