commit 1d7c4420d1d212aa08060d214236bf677e768ac3 from: Stefan Sperling date: Sat Dec 28 13:39:30 2024 UTC store ibuf used by got_repo_read_gitconfig() on the stack commit - d8cbc463e9dcdeb0d1ae12ab9f2d1de58f141b14 commit + 1d7c4420d1d212aa08060d214236bf677e768ac3 blob - 1383324346b66adf41e2c9542956187a27b2cdf9 blob + 888590ed15c13705cc6d56675504992831a23950 --- lib/read_gitconfig_privsep.c +++ lib/read_gitconfig_privsep.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -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; }