File 0003-get-log-Make-log-identifier-a-required-parameter.patch of Package nvme-cli.10367

From: Keith Busch <keith.busch@intel.com>
Date: Mon, 19 Mar 2018 16:55:34 -0600
Subject: get-log: Make log identifier a required parameter

Git-commit: 44044e6c3c6fc1d4813163d5054c0750ef88ee06
References: bsc#1086240

If you're using the generic get-log, make sure the user specifies the
log parameter. It would be a user error if they don't as they should
never be counting on a default parameter.

Link: https://github.com/linux-nvme/nvme-cli/pull/320
Signed-off-by: Keith Busch <keith.busch@intel.com>
---
 nvme.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

--- a/nvme.c
+++ b/nvme.c
@@ -409,7 +409,7 @@ static int get_log(int argc, char **argv
 
 	struct config cfg = {
 		.namespace_id = NVME_NSID_ALL,
-		.log_id       = 0,
+		.log_id       = 0xffffffff,
 		.log_len      = 0,
 	};
 
@@ -431,9 +431,16 @@ static int get_log(int argc, char **argv
 		cfg.log_id = (cfg.aen >> 16) & 0xff;
 	}
 
+	if (cfg.log_id > 0xff) {
+		fprintf(stderr, "Invalid log identifier: %d. Valid range: 0-255\n", cfg.log_id);
+		err = EINVAL;
+		goto close_fd;
+	}
+
 	if (!cfg.log_len) {
 		fprintf(stderr, "non-zero log-len is required param\n");
-		return EINVAL;
+		err = EINVAL;
+		goto close_fd;
 	} else {
 		unsigned char *log;
 
@@ -457,9 +464,14 @@ static int get_log(int argc, char **argv
 						nvme_status_to_string(err), err);
 		else
 			perror("log page");
+		close(fd);
 		free(log);
 		return err;
 	}
+
+close_fd:
+	close(fd);
+	return err;
 }
 
 static const char * sanitize_mon_status_to_string(__u16 status)
openSUSE Build Service is sponsored by