From 840f79fd82839b6031c67f22e955aa87395ffb45 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 8 Mar 2026 20:50:44 +0000 Subject: util/nvmutil: only close gbe fd if opened Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index d7cd943c..7cc782c8 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -372,8 +372,10 @@ main(int argc, char *argv[]) else if (gbe_flags != O_RDONLY) write_gbe_file(); - if (close(gbe_fd) == -1) - err(ECANCELED, "close '%s'", fname); + if (gbe_fd > -1) { + if (close(gbe_fd) == -1) + err(ECANCELED, "close '%s'", fname); + } #ifndef HAVE_ARC4RANDOM_BUF if (urandom_fd > -1) { @@ -694,6 +696,11 @@ read_gbe_file_part(size_t p) GBE_PART_SIZE, gbe_file_offset(p, "pread"), fname, "pread"); } +/* + * This is the first defense, but individual + * commands should still perform checksum + * verification where indicated, as a fallback. + */ static void read_checksums(void) { -- cgit v1.2.1