From: Colin Ian King Date: Thu, 2 Jun 2016 18:11:52 +0000 (+0100) Subject: Fix segmentation fault using nvme show-regs with no device name X-Git-Tag: v0.8~44^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=91c61f187fc953e149a648b9c7108945848132af;p=users%2Fsagi%2Fnvme-cli.git Fix segmentation fault using nvme show-regs with no device name Add check_arg_dev() to check if a device name has been provided and use this in show_registers to avoid the following segfault: Segmentation fault (core dumped) Signed-off-by: Colin Ian King --- diff --git a/nvme.c b/nvme.c index 6626ed1c..8ba67de2 100644 --- a/nvme.c +++ b/nvme.c @@ -165,13 +165,18 @@ static void open_dev(const char *dev) exit(errno); } -static void get_dev(int argc, char **argv) +static void check_arg_dev(int argc, char **argv) { if (optind >= argc) { errno = EINVAL; perror(argv[0]); exit(errno); } +} + +static void get_dev(int argc, char **argv) +{ + check_arg_dev(argc, argv); open_dev((const char *)argv[optind]); } @@ -1263,6 +1268,8 @@ static int show_registers(int argc, char **argv) while ((opt = getopt_long(argc, (char **)argv, "", NULL, &long_index)) != -1); + + check_arg_dev(argc, argv); devicename = basename(argv[optind]); get_registers(&bar);