"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Lucas <lucas@sexy.is>
Subject:
got_repo_pack_fds_close: don't close(0)
To:
gameoftrees@openbsd.org
Date:
Thu, 21 Jul 2022 17:21:50 +0000

Download raw body.

Thread
  • Lucas:

    got_repo_pack_fds_close: don't close(0)

Hey all,

Patch to avoid closing fd 0. I'm not 100% sure if memset(a, -1, n) works
for all arches, but I can change the patch to use that if preferred.


diff /home/lucas/code/git/git.gameoftrees.org/got
commit - c46eda88bcbbcf577ca7a805746b44d63c0e4c0a
path + /home/lucas/code/git/git.gameoftrees.org/got
blob - 1afcaaffa734eb472002229d279079cb970029da
file + lib/repository.c
--- lib/repository.c
+++ lib/repository.c
@@ -263,6 +263,14 @@ got_repo_pack_fds_open(int **pack_fds)
 		return got_error_from_errno("calloc");
 	}
 
+	/*
+	 * got_repo_pack_fds_close will try to close all of the
+	 * GOT_PACK_NUM_TEMPFILES fds, even the ones that didn't manage to get
+	 * a value from got_opentempfd(), resulting in a close(0).
+	 */
+	for (i = 0; i < GOT_PACK_NUM_TEMPFILES; i++)
+		pack_fds_tmp[i] = -1;
+
 	for (i = 0; i < GOT_PACK_NUM_TEMPFILES; i++) {
 		pack_fds_tmp[i] = got_opentempfd();
 		if (pack_fds_tmp[i] == -1) {