Message ID | 1463791855-24615-2-git-send-email-vishal.l.verma@intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 0f50e5814dad |
Headers | show |
On Fri, May 20, 2016 at 06:50:54PM -0600, Vishal Verma wrote: > Running something like ndctl create-namespace --list-cmds > would reliably sigfault ndctl due to a null pointer dereference. > > Add a check before the dereference to fix it. > > Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
diff --git a/util/parse-options.c b/util/parse-options.c index f170eb0..387eecd 100644 --- a/util/parse-options.c +++ b/util/parse-options.c @@ -472,8 +472,9 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o } exit(130); case PARSE_OPT_LIST_SUBCMDS: - for (int i = 0; subcommands[i]; i++) - printf("%s ", subcommands[i]); + if (subcommands) + for (int i = 0; subcommands[i]; i++) + printf("%s ", subcommands[i]); exit(130); default: /* PARSE_OPT_UNKNOWN */ if (ctx.argv[0][1] == '-') {
Running something like ndctl create-namespace --list-cmds would reliably sigfault ndctl due to a null pointer dereference. Add a check before the dereference to fix it. Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> --- util/parse-options.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)