Skip to contentSkip to conversation

tools/libxl: Fix two errors with libxl_userdata_unlink()

PATCH In review Andrew Cooper 4 participants 6 messages Sep 24, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxl: Fix two errors with libxl_userdata_unlink()

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.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_dom.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_dom.c +2 -2
index bd21841..11c2683 100644
@@ -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:
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andrew Cooper

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.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>

Thanks for fixing this up.

Wei.

#2 lore raw
In reply to Andrew Cooper
Quoted 2 lines · Andrew Cooper

Coverity-ID: 1240235
* filename may be NULL, at which point calling unlink() would be unwise.

Oops!

Quoted 2 lines

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.

Quoted 31 lines
CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_dom.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_dom.c +2 -2
index bd21841..11c2683 100644
@@ -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:
#3 lore raw
Quoted 9 lines · Ian Campbell
Quoted 2 lines · Andrew Cooper

Coverity-ID: 1240235
* filename may be NULL, at which point calling unlink() would be unwise.

Oops!

Quoted 2 lines

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

Quoted 32 lines
Quoted 31 lines
CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_dom.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_dom.c +2 -2
index bd21841..11c2683 100644
@@ -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:
#4 lore raw

Andrew Cooper writes ("Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()"):

Quoted 1 line

Good point - v2 incoming.

Just spotted this reply from Andrew. I have my own version just posted.

Ian.

#5 lore raw
In reply to Ian Campbell

Ian Campbell writes ("Re: [PATCH] tools/libxl: Fix two errors with libxl_userdata_unlink()"):

Quoted 2 lines

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.