diff mbox

[1/3] util_namespace_to_json: fix potential null pointer dereference

Message ID 20160623195950.30968-2-jmoyer@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jeff Moyer June 23, 2016, 7:59 p.m. UTC
Coverity pointed out that "dax" could be NULL, and it goes unchecked.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
---
 ndctl/util/json.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Dan Williams June 23, 2016, 8:12 p.m. UTC | #1
On Thu, Jun 23, 2016 at 12:59 PM, Jeff Moyer <jmoyer@redhat.com> wrote:
> Coverity pointed out that "dax" could be NULL, and it goes unchecked.
>
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
> ---
>  ndctl/util/json.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/ndctl/util/json.c b/ndctl/util/json.c
> index d144039..92e50fa 100644
> --- a/ndctl/util/json.c
> +++ b/ndctl/util/json.c
> @@ -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.
diff mbox

Patch

diff --git a/ndctl/util/json.c b/ndctl/util/json.c
index d144039..92e50fa 100644
--- a/ndctl/util/json.c
+++ b/ndctl/util/json.c
@@ -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;