Misc. ndctl fixes
cover Misc. ndctl fixes
Static checkers turned up a few potential problems in the code. This series fixes them.
Cheers,
Jeff
[PATCH 1/3] util_namespace_to_json: fix potential null pointer [PATCH 2/3] daxctl_region_unref: fix a potential null pointer [PATCH 3/3] validate_namespace_options: fix bogus test
A message that is not in the archive (sent off-list or not yet received): 20160623195950.30968-1-jmoyer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
PATCH 1/3 util_namespace_to_json: fix potential null pointer dereference
Coverity pointed out that "dax" could be NULL, and it goes unchecked.
--- ndctl/util/json.c | 2 ++ 1 file changed, 2 insertions(+)
ndctl/util/json.c +2 -0
@@ -133,6 +133,8 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) jobj =json_object_new_string ("memory" );break ;case NDCTL_NS_MODE_DAX : +if (!dax) + goto err; size =ndctl_dax_get_size (dax); jobj =json_object_new_string ("dax" );break ;
Signature · 1 line
2.8.2.335.g4bb51ae
A message that is not in the archive (sent off-list or not yet received): 20160623195950.30968-2-jmoyer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [PATCH 1/3] util_namespace_to_json: fix potential null pointer dereference
Quoted 12 lines · Jeff Moyer
Coverity pointed out that "dax" could be NULL, and it goes unchecked.
Signed-off-by Jeff Moyer <[email protected]>--- ndctl/util/json.c | 2 ++ 1 file changed, 2 insertions(+)ndctl/util/json.c +0
-0
ndctl/util/json.c struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) · line 140
Quoted 8 lines
ndctl/util/json.c +2
-0@@ -133,6 +133,8 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) jobj =json_object_new_string ("memory" );break ;case NDCTL_NS_MODE_DAX : +if (!dax) + goto err; size =ndctl_dax_get_size (dax); jobj =json_object_new_string ("dax" );break ;
The other patches look good, this one points out a problem with ndctl_namespace_get_mode() which should be using a cached value rather reading it from sysfs directly. When we snapshot it with a cached value it becomes impossible to have ndctl_namespace_get_mode() == NDCTL_NS_MODE_DAX and ndctl_namespace_get_dax() == NULL.
PATCH 2/3 daxctl_region_unref: fix a potential null pointer dereference
In reply to a message not in the archiveMove the assignment of ctx to after the NULL check.
--- daxctl/lib/libdaxctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
daxctl/lib/libdaxctl.c +2 -1
@@ -181,7 +181,7 @@ static void free_dev(struct daxctl_dev *dev, struct list_head *head) DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region) { -struct daxctl_ctx *ctx = region->ctx; +struct daxctl_ctx *ctx;struct daxctl_dev *dev, *_d;if (!region)
@@ -190,6 +190,7 @@ DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region)if (region->refcount)return ; + ctx = region->ctx;info (ctx,"region%d released\n" , region->id);list_for_each_safe (®ion->devices, dev, _d, list)free_dev (dev, ®ion->devices);
Signature · 1 line
2.8.2.335.g4bb51ae
PATCH 3/3 validate_namespace_options: fix bogus test
In reply to a message not in the archiveAnother coverity find. The patch is self-explanatory, I hope.
--- ndctl/builtin-xaction-namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ndctl/builtin-xaction-namespace.c +2 -1
@@ -444,7 +444,8 @@ static int validate_namespace_options(struct ndctl_region *region, ndctl_namespace_get_devname(ndns));return -EINVAL ; } - }else if (p->mode ==NDCTL_NS_MODE_MEMORY ||NDCTL_NS_MODE_DAX ) + }else if (p->mode ==NDCTL_NS_MODE_MEMORY || + p->mode ==NDCTL_NS_MODE_DAX ) p->loc =NDCTL_PFN_LOC_PMEM ;/* check if we need, and whether the kernel supports, pfn devices */
Signature · 1 line
2.8.2.335.g4bb51ae