Commit Diff


commit - 176a525f12805253c6786c12f171feaa38da2902420b646298d5b97d622b2817
commit + 5f989f2afdba9ad2b0d212417a547cf8e5e03bb76b628b6b779457315743a8ed
blob - 2a8dadd86cca5456e7442105f243259b5e68a3e42966d78a1f1f18795c8cc868
blob + 8051e5608281bc7277f83cc7128a4e9359fc4f0a068ceb3076f7ee26ccb16558
--- lib/read_gitconfig_privsep.c	
+++ lib/read_gitconfig_privsep.c	
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <string.h>
 #include <imsg.h>
 #include <unistd.h>
 
@@ -56,8 +57,10 @@ got_repo_read_gitconfig(int *gitconfig_repository_form
 	int fd = -1;
 	int imsg_fds[2] = { -1, -1 };
 	pid_t pid;
-	struct imsgbuf *ibuf;
+	struct imsgbuf ibuf;
 
+	memset(&ibuf, 0, sizeof(ibuf));
+
 	*gitconfig_repository_format_version = 0;
 	if (extnames)
 		*extnames = NULL;
@@ -81,12 +84,6 @@ got_repo_read_gitconfig(int *gitconfig_repository_form
 		return got_error_from_errno2("open", gitconfig_path);
 	}
 
-	ibuf = calloc(1, sizeof(*ibuf));
-	if (ibuf == NULL) {
-		err = got_error_from_errno("calloc");
-		goto done;
-	}
-
 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
 		err = got_error_from_errno("socketpair");
 		goto done;
@@ -107,32 +104,32 @@ got_repo_read_gitconfig(int *gitconfig_repository_form
 		goto wait;
 	}
 	imsg_fds[1] = -1;
-	if (imsgbuf_init(ibuf, imsg_fds[0]) == -1) {
+	if (imsgbuf_init(&ibuf, imsg_fds[0]) == -1) {
 		err = got_error_from_errno("imsgbuf_init");
 		goto wait;
 	}
-	imsgbuf_allow_fdpass(ibuf);
+	imsgbuf_allow_fdpass(&ibuf);
 
-	err = got_privsep_send_gitconfig_parse_req(ibuf, fd);
+	err = got_privsep_send_gitconfig_parse_req(&ibuf, fd);
 	if (err)
 		goto wait;
 	fd = -1;
 
-	err = got_privsep_send_gitconfig_repository_format_version_req(ibuf);
+	err = got_privsep_send_gitconfig_repository_format_version_req(&ibuf);
 	if (err)
 		goto wait;
 
 	err = got_privsep_recv_gitconfig_int(
-	    gitconfig_repository_format_version, ibuf);
+	    gitconfig_repository_format_version, &ibuf);
 	if (err)
 		goto wait;
 
 	if (extnames && extvals && nextensions) {
 		err = got_privsep_send_gitconfig_repository_extensions_req(
-		    ibuf);
+		    &ibuf);
 		if (err)
 			goto wait;
-		err = got_privsep_recv_gitconfig_int(nextensions, ibuf);
+		err = got_privsep_recv_gitconfig_int(nextensions, &ibuf);
 		if (err)
 			goto wait;
 		if (*nextensions > 0) {
@@ -150,7 +147,7 @@ got_repo_read_gitconfig(int *gitconfig_repository_form
 			for (i = 0; i < *nextensions; i++) {
 				char *ext, *val;
 				err = got_privsep_recv_gitconfig_pair(&ext,
-				    &val, ibuf);
+				    &val, &ibuf);
 				if (err)
 					goto wait;
 				(*extnames)[i] = ext;
@@ -159,38 +156,38 @@ got_repo_read_gitconfig(int *gitconfig_repository_form
 		}
 	}
 
-	err = got_privsep_send_gitconfig_author_name_req(ibuf);
+	err = got_privsep_send_gitconfig_author_name_req(&ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_recv_gitconfig_str(gitconfig_author_name, ibuf);
+	err = got_privsep_recv_gitconfig_str(gitconfig_author_name, &ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_send_gitconfig_author_email_req(ibuf);
+	err = got_privsep_send_gitconfig_author_email_req(&ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_recv_gitconfig_str(gitconfig_author_email, ibuf);
+	err = got_privsep_recv_gitconfig_str(gitconfig_author_email, &ibuf);
 	if (err)
 		goto wait;
 
 	if (remotes && nremotes) {
-		err = got_privsep_send_gitconfig_remotes_req(ibuf);
+		err = got_privsep_send_gitconfig_remotes_req(&ibuf);
 		if (err)
 			goto wait;
 
 		err = got_privsep_recv_gitconfig_remotes(remotes,
-		    nremotes, ibuf);
+		    nremotes, &ibuf);
 		if (err)
 			goto wait;
 	}
 
 	if (gitconfig_owner) {
-		err = got_privsep_send_gitconfig_owner_req(ibuf);
+		err = got_privsep_send_gitconfig_owner_req(&ibuf);
 		if (err)
 			goto wait;
-		err = got_privsep_recv_gitconfig_str(gitconfig_owner, ibuf);
+		err = got_privsep_recv_gitconfig_str(gitconfig_owner, &ibuf);
 		if (err)
 			goto wait;
 	}
@@ -207,7 +204,7 @@ done:
 		err = got_error_from_errno("close");
 	if (fd != -1 && close(fd) == -1 && err == NULL)
 		err = got_error_from_errno2("close", gitconfig_path);
-	imsgbuf_clear(ibuf);
-	free(ibuf);
+	if (ibuf.w)
+		imsgbuf_clear(&ibuf);
 	return err;
 }