commit 4ea1597e9427b3edc4b5fc4a3c432fea5c2ef590 from: Stefan Sperling via: Thomas Adam date: Fri Jan 03 10:46:48 2025 UTC store ibuf used by got_gotconfig_read() on the stack commit - 8895ea222744600a0ef6af534f826a50bd3a4d6d commit + 4ea1597e9427b3edc4b5fc4a3c432fea5c2ef590 blob - a9093242d97dc5f5a7222516e46832499389b80c blob + 3ea500f48796ec2e55650ffe6bdbc9aec79a5219 --- lib/read_gotconfig_privsep.c +++ lib/read_gotconfig_privsep.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -48,8 +49,10 @@ got_gotconfig_read(struct got_gotconfig **conf, const int fd = -1; int imsg_fds[2] = { -1, -1 }; pid_t pid; - struct imsgbuf *ibuf = NULL; + struct imsgbuf ibuf; + memset(&ibuf, 0, sizeof(ibuf)); + *conf = calloc(1, sizeof(**conf)); if (*conf == NULL) return got_error_from_errno("calloc"); @@ -62,12 +65,6 @@ got_gotconfig_read(struct got_gotconfig **conf, const goto done; } - 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; @@ -88,57 +85,57 @@ got_gotconfig_read(struct got_gotconfig **conf, const 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_gotconfig_parse_req(ibuf, fd); + err = got_privsep_send_gotconfig_parse_req(&ibuf, fd); if (err) goto wait; fd = -1; - err = got_privsep_send_gotconfig_author_req(ibuf); + err = got_privsep_send_gotconfig_author_req(&ibuf); if (err) goto wait; - err = got_privsep_recv_gotconfig_str(&(*conf)->author, ibuf); + err = got_privsep_recv_gotconfig_str(&(*conf)->author, &ibuf); if (err) goto wait; - err = got_privsep_send_gotconfig_allowed_signers_req(ibuf); + err = got_privsep_send_gotconfig_allowed_signers_req(&ibuf); if (err) goto wait; err = got_privsep_recv_gotconfig_str(&(*conf)->allowed_signers_file, - ibuf); + &ibuf); if (err) goto wait; - err = got_privsep_send_gotconfig_revoked_signers_req(ibuf); + err = got_privsep_send_gotconfig_revoked_signers_req(&ibuf); if (err) goto wait; err = got_privsep_recv_gotconfig_str(&(*conf)->revoked_signers_file, - ibuf); + &ibuf); if (err) goto wait; - err = got_privsep_send_gotconfig_signer_id_req(ibuf); + err = got_privsep_send_gotconfig_signer_id_req(&ibuf); if (err) goto wait; - err = got_privsep_recv_gotconfig_str(&(*conf)->signer_id, ibuf); + err = got_privsep_recv_gotconfig_str(&(*conf)->signer_id, &ibuf); if (err) goto wait; - err = got_privsep_send_gotconfig_remotes_req(ibuf); + err = got_privsep_send_gotconfig_remotes_req(&ibuf); if (err) goto wait; err = got_privsep_recv_gotconfig_remotes(&(*conf)->remotes, - &(*conf)->nremotes, ibuf); + &(*conf)->nremotes, &ibuf); if (err) goto wait; wait: @@ -158,7 +155,7 @@ done: got_gotconfig_free(*conf); *conf = NULL; } - imsgbuf_clear(ibuf); - free(ibuf); + if (ibuf.w) + imsgbuf_clear(&ibuf); return err; }