[ndctl PATCH 4/5] ndctl, test: fix a potential null pointer dereference in 'ndctl test'

Vishal Verma
2018-08-10T22:56:31Z

Static analysis reports that we can potentially dereference a null
pointer in the above function. Fix by checking the return value from the
allocation.

Cc: Dan Williams <dan.j.williams@intel.com>
Fixes: 8229da8d73a3 ("ndctl: ship the unit test as 'ndctl test'")
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
ndctl/test.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/ndctl/test.c b/ndctl/test.c
index 285594f..25ec61c 100644
--- a/ndctl/test.c
+++ b/ndctl/test.c
@@ -55,6 +55,8 @@ int cmd_test(int argc, const char **argv, void *ctx)
test = ndctl_test_new(UINT_MAX);
else
test = ndctl_test_new(0);
+ if (!test)
+ return EXIT_FAILURE;

rc = test_libndctl(loglevel, test, ctx);
fprintf(stderr, "test-libndctl: %s\n", result(rc));