|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: Fix error handling in libxl_userdata_unlink
commit 9fe1ab70752d81a65b2a1492c46d9119438c0e9e
Author: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
AuthorDate: Wed Sep 24 15:22:08 2014 +0100
Commit: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Wed Oct 8 11:51:37 2014 +0100
libxl: Fix error handling in libxl_userdata_unlink
Previously:
* rc would not be set before leaving the function, with the
result that an uninitialised value would be returned
* failures of libxl__userdata_path would result in a NULL dereference
* failures of unlink() would not be usefully logged
This appears to be due to an attempt to avoid having to repeat the
call to libxl__unlock_domain_userdata by informally sharing parts of
the success and failure paths.
Change to use the canonical error-handling style:
* Initialise lock to 0.
* Do the unlock in the `out' section - always attempt to unlock
lock if it is non-0.
* Explicitly set rc and `goto out' on all error paths, even
those right at the end of the function.
* Add an error check for filename = libxl__userdata_path(...);
Coverity-ID: 1240237, 1240235.
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
CC: coverity@xxxxxxxxxxxxxx
Reviewed-by: Andrew Cooper<andrew.cooper3@xxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
tools/libxl/libxl_dom.c | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index d63ae1b..9d830e1 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -2243,12 +2243,12 @@ int libxl_userdata_unlink(libxl_ctx *ctx, uint32_t
domid,
const char *userdata_userid)
{
GC_INIT(ctx);
- int rc;
+ CTX_LOCK;
- libxl__domain_userdata_lock *lock;
+ int rc;
+ libxl__domain_userdata_lock *lock = NULL;
const char *filename;
- CTX_LOCK;
lock = libxl__lock_domain_userdata(gc, domid);
if (!lock) {
rc = ERROR_LOCK_FAIL;
@@ -2256,10 +2256,20 @@ 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) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ if (unlink(filename)) {
+ LOGE(ERROR, "error deleting userdata file: %s", filename);
+ rc = ERROR_FAIL;
+ goto out;
+ }
- libxl__unlock_domain_userdata(lock);
+ rc = 0;
out:
+ if (lock)
+ libxl__unlock_domain_userdata(lock);
CTX_UNLOCK;
GC_FREE;
return rc;
--
generated by git-patchbot for /home/xen/git/xen.git#master
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |