Thread (1 message) 1 message, 1 author, 2021-02-26

Re: [PATCH] pack-revindex.c: don't close unopened file descriptors

From: Junio C Hamano <hidden>
Date: 2021-02-26 22:42:25

Taylor Blau [off-list ref] writes:
When opening a reverse index, load_revindex_from_disk() jumps to the
'cleanup' label in case something goes wrong: the reverse index had the
wrong size, an unrecognized version, or similar.

It also jumps to this label when the reverse index couldn't be opened in
the first place, which will cause an error with the unguarded close()
call in the label.

Guard this call with "if (fd >= 0)" to make sure that we have a valid
file descriptor to close before attempting to close it.

Reported-by: Johannes Schindelin <redacted>
Signed-off-by: Taylor Blau <redacted>
---
Dscho mentioned this to me privately when reviewing Coverity results for
-rc0. This one is legitimate, and the fix is easy enough, too.
Thanks, both.
quoted hunk
 pack-revindex.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pack-revindex.c b/pack-revindex.c
index 83fe4de773..4262530449 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -253,7 +253,8 @@ static int load_revindex_from_disk(char *revindex_name,
 		*data_p = (const uint32_t *)data;
 	}

-	close(fd);
+	if (fd >= 0)
+		close(fd);
 	return ret;
 }

--
2.30.0.667.g81c0cbc6fd
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help