From e73085f88b8845d6421588f94e107db36ee2b1b2 Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 31 Jan 2024 06:54:43 +0000 Subject: [PATCH] Rename mft_compare() to mft_compare_seqnum() This makes it clearer what exactly this function compares. Also drop some NULL checks that made the semantics of this function tricky. ok job --- usr.sbin/rpki-client/extern.h | 4 ++-- usr.sbin/rpki-client/mft.c | 13 +++---------- usr.sbin/rpki-client/parser.c | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 61527fdefb5..7245536c8bf 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.199 2024/01/18 14:34:26 job Exp $ */ +/* $OpenBSD: extern.h,v 1.200 2024/01/31 06:54:43 tb Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -629,7 +629,7 @@ void mft_free(struct mft *); struct mft *mft_parse(X509 **, const char *, int, const unsigned char *, size_t); struct mft *mft_read(struct ibuf *); -int mft_compare(const struct mft *, const struct mft *); +int mft_compare_seqnum(const struct mft *, const struct mft *); void roa_buffer(struct ibuf *, const struct roa *); void roa_free(struct roa *); diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index 8fd3755f1c9..17ddda63427 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.100 2023/12/11 15:50:23 job Exp $ */ +/* $OpenBSD: mft.c,v 1.101 2024/01/31 06:54:43 tb Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2019 Kristaps Dzonsons @@ -545,20 +545,13 @@ mft_read(struct ibuf *b) } /* - * Compare the manifestNumber of two MFT files. - * Returns 1 if first MFT should be used, 0 if both are equal, and -1 if the - * second MFT should be used. + * Compare the manifestNumber of two mft files. */ int -mft_compare(const struct mft *a, const struct mft *b) +mft_compare_seqnum(const struct mft *a, const struct mft *b) { int r; - if (b == NULL) - return 1; - if (a == NULL) - return -1; - r = strlen(a->seqnum) - strlen(b->seqnum); if (r > 0) /* seqnum in a is longer -> higher */ return 1; diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 3d89f9bf615..ab57a2e483b 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.111 2024/01/31 06:53:21 tb Exp $ */ +/* $OpenBSD: parser.c,v 1.112 2024/01/31 06:54:43 tb Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -315,7 +315,7 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, * a smaller sequence number. */ - if ((seqnum_cmp = mft_compare(mft, cached_mft)) < 0) { + if ((seqnum_cmp = mft_compare_seqnum(mft, cached_mft)) < 0) { warnx("%s: unexpected manifest number (want >= #%s, got #%s)", *file, cached_mft->seqnum, mft->seqnum); goto err; -- 2.20.1