commit aac02238e5d3974fdc3636fe328c80c768389173 from: Stefan Sperling date: Sat Dec 28 13:41:08 2024 UTC store ibuf used by got_gotconfig_read() on the stack commit - 1d7c4420d1d212aa08060d214236bf677e768ac3 commit + aac02238e5d3974fdc3636fe328c80c768389173 blob - 70c6265c3781e01cedf23fba2769c037a95528b0 blob + 5f13405753a28a8fea6effbce3e04fe25c3a70aa --- lib/read_gotconfig_privsep.c +++ lib/read_gotconfig_privsep.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -49,8 +50,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"); @@ -63,12 +66,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; @@ -89,57 +86,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: @@ -159,7 +156,7 @@ done: got_gotconfig_free(*conf); *conf = NULL; } - imsgbuf_clear(ibuf); - free(ibuf); + if (ibuf.w) + imsgbuf_clear(&ibuf); return err; }