Blame SOURCES/0004-nvme-do-not-leak-an-open-file-handle.patch

955b2d
From 45223fd3c5a13da9209c4f44d7593cb42cab94fb Mon Sep 17 00:00:00 2001
955b2d
From: Maurizio Lombardi <mlombard@redhat.com>
955b2d
Date: Tue, 14 Dec 2021 10:09:42 +0100
955b2d
Subject: [PATCH 3/6] nvme: do not leak an open file handle
955b2d
955b2d
We performed a "sec_fd=open(cfg.file)" earlier, so we should not
955b2d
overwrite the handle.
955b2d
955b2d
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
955b2d
---
955b2d
 nvme.c | 9 +--------
955b2d
 1 file changed, 1 insertion(+), 8 deletions(-)
955b2d
955b2d
diff --git a/nvme.c b/nvme.c
955b2d
index 862f9b6..5beeac7 100644
955b2d
--- a/nvme.c
955b2d
+++ b/nvme.c
955b2d
@@ -4379,17 +4379,10 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p
955b2d
 		fprintf(stderr, "WARNING: --tl not dword aligned; unaligned bytes may be truncated\n");
955b2d
 
955b2d
 	if (strlen(cfg.file) == 0) {
955b2d
+		close(sec_fd);
955b2d
 		sec_fd = STDIN_FILENO;
955b2d
 		sec_size = cfg.tl;
955b2d
 	} else {
955b2d
-		sec_fd = open(cfg.file, O_RDONLY);
955b2d
-		if (sec_fd < 0) {
955b2d
-			fprintf(stderr, "Failed to open %s: %s\n",
955b2d
-					cfg.file, strerror(errno));
955b2d
-			err = -EINVAL;
955b2d
-			goto close_fd;
955b2d
-		}
955b2d
-
955b2d
 		err = fstat(sec_fd, &sb);
955b2d
 		if (err < 0) {
955b2d
 			perror("fstat");
955b2d
-- 
955b2d
2.27.0
955b2d