From: Baptiste Daroussin Date: Wed, 8 Mar 2023 10:08:08 +0000 (+0100) Subject: mlmmj-send: multiple fixes: X-Git-Tag: RELEASE_1_4_0b1~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96955980570f6ba25e22d208f98c72015e16f800;p=thirdparty%2Fmlmmj.git mlmmj-send: multiple fixes: fix possible use heap-after-free allow passing mailarchive via file descriptor --- diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index bd3c1003..b601573f 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -322,7 +322,10 @@ int send_mail_many_list(int sockfd, struct mail *mail, strlist *addrs, } mail->to = addr; res = send_mail(sockfd, mail, listfd, ctrlfd, bounceaddr != NULL); - free(bounceaddr); + if (bounceaddr != NULL) { + free(bounceaddr); + mail->from = NULL; + } if(res && listaddr && archivefilename) { /* we failed, so save the addresses and bail */ index = get_index_from_filename(archivefilename); @@ -485,8 +488,16 @@ int main(int argc, char **argv) if ((mailfd = open(mailfilename, O_RDWR)) == -1 || !lock(mailfd, true)) { - log_error(LOG_ARGS, "Could not open '%s'", mailfilename); - exit(EXIT_FAILURE); + if (ml.dir != NULL && mailfd == -1) { + if ((mailfd = openat(ml.fd, mailfilename, O_RDWR)) == -1 || + !lock(mailfd, true)) { + log_error(LOG_ARGS, "Could not open '%s'", mailfilename); + exit(EXIT_FAILURE); + } + } else { + log_error(LOG_ARGS, "Could not open '%s'", mailfilename); + exit(EXIT_FAILURE); + } } mail.fp = fdopen(mailfd, "r");