From 6747684d5a721ee9d8c50ebce6f0c51b3a5ef719 Mon Sep 17 00:00:00 2001 From: job Date: Mon, 7 Nov 2022 16:23:32 +0000 Subject: [PATCH] Simplify use of strrchr() with and OK tb@ --- usr.sbin/rpki-client/cert.c | 10 +++++++--- usr.sbin/rpki-client/mft.c | 16 +++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/usr.sbin/rpki-client/cert.c b/usr.sbin/rpki-client/cert.c index 92bc54bb34d..2ce5f63e592 100644 --- a/usr.sbin/rpki-client/cert.c +++ b/usr.sbin/rpki-client/cert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cert.c,v 1.95 2022/11/04 12:05:36 tb Exp $ */ +/* $OpenBSD: cert.c,v 1.96 2022/11/07 16:23:32 job Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2021 Job Snijders @@ -475,8 +475,12 @@ sbgp_sia(struct parse *p, X509_EXTENSION *ext) } mftfilename = strrchr(p->res->mft, '/'); - if (mftfilename == NULL || !valid_filename(mftfilename + 1, - strlen(mftfilename) - 1)) { + if (mftfilename == NULL) { + warnx("%s: SIA: invalid rpkiManifest entry", p->fn); + goto out; + } + mftfilename++; + if (!valid_filename(mftfilename, strlen(mftfilename))) { warnx("%s: SIA: rpkiManifest filename contains invalid " "characters", p->fn); goto out; diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index b86775e7705..097ec7a6691 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.77 2022/11/04 09:43:13 job Exp $ */ +/* $OpenBSD: mft.c,v 1.78 2022/11/07 16:23:32 job Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2019 Kristaps Dzonsons @@ -392,14 +392,20 @@ mft_parse(X509 **x509, const char *fn, const unsigned char *der, size_t len) "missing CRL distribution point extension", fn); goto out; } - if ((crlfile = strrchr(crldp, '/')) == NULL || - !valid_mft_filename(crlfile + 1, strlen(crlfile + 1)) || - rtype_from_file_extension(crlfile + 1) != RTYPE_CRL) { + crlfile = strrchr(crldp, '/'); + if (crlfile == NULL) { + warnx("%s: RFC 6487 section 4.8.6: " + "invalid CRL distribution point", fn); + goto out; + } + crlfile++; + if (!valid_mft_filename(crlfile, strlen(crlfile)) || + rtype_from_file_extension(crlfile) != RTYPE_CRL) { warnx("%s: RFC 6487 section 4.8.6: CRL: " "bad CRL distribution point extension", fn); goto out; } - if ((p.res->crl = strdup(crlfile + 1)) == NULL) + if ((p.res->crl = strdup(crlfile)) == NULL) err(1, NULL); if (mft_parse_econtent(cms, cmsz, &p) == 0) -- 2.20.1