diff mbox

[ndctl,5/6] libdaxctl: fix deref-before-null-check in daxctl_new_region

Message ID 147432108766.39548.6131939956705403033.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams Sept. 19, 2016, 9:38 p.m. UTC
If ->region_path is not set, do not attempt to take its length.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 daxctl/lib/libdaxctl.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index ecdb99640115..8f1b88e06ac6 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -217,14 +217,19 @@  DAXCTL_EXPORT struct daxctl_region *daxctl_new_region(struct daxctl_ctx *ctx,
 	region->id = id;
 	region->refcount = 1;
 	uuid_copy(region->uuid, uuid);
+
 	region->region_path = strdup(path);
+	if (!region->region_path) {
+		free(region);
+		return NULL;
+	}
+
 	list_head_init(&region->devices);
 	region->buf_len = strlen(region->region_path) + REGION_BUF_SIZE;
 	region->region_buf = calloc(1, region->buf_len);
-
-	if (!region->region_path || !region->region_buf) {
+	if (!region->region_buf) {
 		daxctl_region_unref(region);
-		region = NULL;
+		return NULL;
 	}
 
 	dbg(ctx, "%s: %s\n", __func__, daxctl_region_get_devname(region));