From: tb Date: Fri, 2 Feb 2024 22:09:56 +0000 (+0000) Subject: Rework proc_parser_mft() further X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=94674fa34e3c213b95e39c564a2560f0d915e814;p=openbsd Rework proc_parser_mft() further By making proc_parser_mft_check() fail on a NULL manifest, we can simplify the manifest selection logic further. This way we can see if the new manifest has all the files it lists with correct hashes and fall back to mft2 if not. This is still more complicated and uglier than it should be, but far les convoluted and mind-bending than a day ago. ok job --- diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 565a9749aac..529c3a90bd2 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.125 2024/02/02 19:31:59 job Exp $ */ +/* $OpenBSD: parser.c,v 1.126 2024/02/02 22:09:56 tb Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -169,6 +169,9 @@ proc_parser_mft_check(const char *fn, struct mft *p) int rc = 1; char *path; + if (p == NULL) + return 0; + for (i = 0; i < p->filesz; i++) { struct mftfile *m = &p->files[i]; int try, fd = -1, noent = 0, valid = 0; @@ -398,41 +401,31 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, &err1); } - if (mft1 != NULL) { - if (proc_parser_mft_check(file1, mft1)) { - *mp = mft1; - } else { - mft_free(mft1); - mft1 = NULL; - if (mft2 != NULL) - warnx("%s: failed fetch, continuing with #%s " - "from cache", file2, mft2->seqnum); - } - } - - if (*mp != NULL) { + if (proc_parser_mft_check(file1, mft1)) { mft_free(mft2); crl_free(crl2); free(crl2file); free(file2); + *mp = mft1; crl = crl1; file = file1; *crlfile = crl1file; } else { - if (mft2 != NULL) { - if (proc_parser_mft_check(file2, mft2)) { - *mp = mft2; - } else { - mft_free(mft2); - mft2 = NULL; - } + if (mft1 != NULL && mft2 != NULL) + warnx("%s: failed fetch, continuing with #%s " + "from cache", file2, mft2->seqnum); + + if (proc_parser_mft_check(file2, mft2)) { + *mp = mft2; } else { + mft_free(mft2); + mft2 = NULL; + if (err2 == NULL) err2 = err1; if (err2 == NULL) - err2 = "no valid mft available"; - /* XXX - file2 == NULL is possible */ + err2 = "no valid manifest available"; warnx("%s: %s", file2, err2); }