Pino Toscano
2017-Nov-03 16:31 UTC
[Libguestfs] [PATCH] daemon: btrfs: fix bad handling of a couple of errors
Remove two wrong error handling situations in btrfs_balance_status:
- if the calloc for 'ret' fails, the 'goto error' would try to
dereference the resulting null pointer (to free the items of the
return struct); hence, just return null directly, instead of jumping
to 'error'
- if the strdup() for 'btrfsbalance_status' fails, then the directly
return would leak 'ret'
---
daemon/btrfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index d363ada6d..26757d4fb 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1686,7 +1686,7 @@ do_btrfs_balance_status (const char *path)
ret = calloc (1, sizeof *ret);
if (ret == NULL) {
reply_with_perror ("calloc");
- goto error;
+ return NULL;
}
/* Output of `btrfs balance status' is like:
@@ -1715,7 +1715,7 @@ do_btrfs_balance_status (const char *path)
ret->btrfsbalance_status = strdup ("none");
if (ret->btrfsbalance_status == NULL) {
reply_with_perror ("strdup");
- return NULL;
+ goto error;
}
return ret;
}
--
2.13.6
Richard W.M. Jones
2017-Nov-03 21:25 UTC
Re: [Libguestfs] [PATCH] daemon: btrfs: fix bad handling of a couple of errors
On Fri, Nov 03, 2017 at 05:31:21PM +0100, Pino Toscano wrote:> Remove two wrong error handling situations in btrfs_balance_status: > - if the calloc for 'ret' fails, the 'goto error' would try to > dereference the resulting null pointer (to free the items of the > return struct); hence, just return null directly, instead of jumping > to 'error' > - if the strdup() for 'btrfsbalance_status' fails, then the directly > return would leak 'ret' > --- > daemon/btrfs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/daemon/btrfs.c b/daemon/btrfs.c > index d363ada6d..26757d4fb 100644 > --- a/daemon/btrfs.c > +++ b/daemon/btrfs.c > @@ -1686,7 +1686,7 @@ do_btrfs_balance_status (const char *path) > ret = calloc (1, sizeof *ret); > if (ret == NULL) { > reply_with_perror ("calloc"); > - goto error; > + return NULL; > } > > /* Output of `btrfs balance status' is like: > @@ -1715,7 +1715,7 @@ do_btrfs_balance_status (const char *path) > ret->btrfsbalance_status = strdup ("none"); > if (ret->btrfsbalance_status == NULL) { > reply_with_perror ("strdup"); > - return NULL; > + goto error; > } > return ret; > } > -- > 2.13.6ACK. These are from Coverity right? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Possibly Parallel Threads
- [PATCH] btrfs_balance_status: delay allocation of 'ret'
- [PATCH] daemon: add a space after func name to fit code-style
- [PATCH v4 0/2] add btrfs_balance_status and btrfs_scrub_status
- [PATCH v4 1/2] New API: btrfs_balance_status
- [PATCH v3 1/2] New API: btrfs_balance_status