]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: add persistent event log action field invalid check
authorGollu Appalanaidu <anaidu.gollu@samsung.com>
Thu, 27 May 2021 06:32:28 +0000 (12:02 +0530)
committerKeith Busch <kbusch@kernel.org>
Fri, 11 Jun 2021 15:56:05 +0000 (09:56 -0600)
Signed-off-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 3ad1cd9915769d41701e123ad837aa151b6151bc..c18ac84e3997b33634c11fbefe1eeb2c8f4d8554 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -913,7 +913,7 @@ static int get_persistent_event_log(int argc, char **argv,
        const char *log_len = "number of bytes to retrieve";
        const char *raw = "use binary output";
        void *pevent_log_info;
-       struct nvme_persistent_event_log_head *pevent_log_head;
+       struct nvme_persistent_event_log_head *pevent_log_head = NULL;
        enum nvme_print_flags flags;
        int err, fd;
        bool huge;
@@ -949,6 +949,13 @@ static int get_persistent_event_log(int argc, char **argv,
        if (cfg.raw_binary)
                flags = BINARY;
 
+       if (cfg.action > 3) {
+               fprintf(stderr, "invalid action field: %u\n", cfg.action);
+               errno = EINVAL;
+               err = -1;
+               goto close_fd;
+       }
+
        pevent_log_head = calloc(sizeof(*pevent_log_head), 1);
        if (!pevent_log_head) {
                perror("could not alloc buffer for persistent " \