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

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