diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-11-13 12:51:05 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-11-13 12:51:05 +0000 |
commit | 6954f6510382cc11f37ac28c1d3ef04ae86480b2 (patch) | |
tree | b8f69cfa902ae23ed52c77b1934c23874577a47a /usr.sbin | |
parent | ee3af04fc73660d1843c934ac0fad85618f3aa23 (diff) |
Second sweep of foosz -> num_foos and friends
Binary change in main.o and tal.o due to an assertion change and in spl.o
due to line number changes
looks good to claudio, ok clang + sha256
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rpki-client/aspa.c | 34 | ||||
-rw-r--r-- | usr.sbin/rpki-client/extern.h | 20 | ||||
-rw-r--r-- | usr.sbin/rpki-client/filemode.c | 4 | ||||
-rw-r--r-- | usr.sbin/rpki-client/main.c | 4 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output-bgpd.c | 6 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output-json.c | 6 | ||||
-rw-r--r-- | usr.sbin/rpki-client/print.c | 24 | ||||
-rw-r--r-- | usr.sbin/rpki-client/repo.c | 16 | ||||
-rw-r--r-- | usr.sbin/rpki-client/rsc.c | 20 | ||||
-rw-r--r-- | usr.sbin/rpki-client/spl.c | 64 | ||||
-rw-r--r-- | usr.sbin/rpki-client/tak.c | 25 | ||||
-rw-r--r-- | usr.sbin/rpki-client/tal.c | 28 |
12 files changed, 128 insertions, 123 deletions
diff --git a/usr.sbin/rpki-client/aspa.c b/usr.sbin/rpki-client/aspa.c index 75c646d237b..b5325a2605a 100644 --- a/usr.sbin/rpki-client/aspa.c +++ b/usr.sbin/rpki-client/aspa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aspa.c,v 1.31 2024/11/05 18:09:16 tb Exp $ */ +/* $OpenBSD: aspa.c,v 1.32 2024/11/13 12:51:03 tb Exp $ */ /* * Copyright (c) 2022 Job Snijders <job@fastly.com> * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> @@ -110,7 +110,7 @@ aspa_parse_providers(const char *fn, struct aspa *aspa, } } - aspa->providers[aspa->providersz++] = provider; + aspa->providers[aspa->num_providers++] = provider; } return 1; @@ -262,9 +262,9 @@ aspa_buffer(struct ibuf *b, const struct aspa *p) io_simple_buffer(b, &p->talid, sizeof(p->talid)); io_simple_buffer(b, &p->expires, sizeof(p->expires)); - io_simple_buffer(b, &p->providersz, sizeof(size_t)); + io_simple_buffer(b, &p->num_providers, sizeof(size_t)); io_simple_buffer(b, p->providers, - p->providersz * sizeof(p->providers[0])); + p->num_providers * sizeof(p->providers[0])); io_str_buffer(b, p->aia); io_str_buffer(b, p->aki); @@ -289,14 +289,14 @@ aspa_read(struct ibuf *b) io_read_buf(b, &p->talid, sizeof(p->talid)); io_read_buf(b, &p->expires, sizeof(p->expires)); - io_read_buf(b, &p->providersz, sizeof(size_t)); + io_read_buf(b, &p->num_providers, sizeof(size_t)); - if (p->providersz > 0) { - if ((p->providers = calloc(p->providersz, + if (p->num_providers > 0) { + if ((p->providers = calloc(p->num_providers, sizeof(p->providers[0]))) == NULL) err(1, NULL); io_read_buf(b, p->providers, - p->providersz * sizeof(p->providers[0])); + p->num_providers * sizeof(p->providers[0])); } io_read_str(b, &p->aia); @@ -315,11 +315,11 @@ aspa_read(struct ibuf *b) static void insert_vap(struct vap *v, uint32_t idx, uint32_t *p) { - if (idx < v->providersz) + if (idx < v->num_providers) memmove(v->providers + idx + 1, v->providers + idx, - (v->providersz - idx) * sizeof(*v->providers)); + (v->num_providers - idx) * sizeof(v->providers[0])); v->providers[idx] = *p; - v->providersz++; + v->num_providers++; } /* @@ -365,7 +365,7 @@ aspa_insert_vaps(char *fn, struct vap_tree *tree, struct aspa *aspa, repo_stat_inc(rp, aspa->talid, RTYPE_ASPA, STYPE_TOTAL); v->providers = reallocarray(v->providers, - v->providersz + aspa->providersz, sizeof(*v->providers)); + v->num_providers + aspa->num_providers, sizeof(v->providers[0])); if (v->providers == NULL) err(1, NULL); @@ -374,8 +374,8 @@ aspa_insert_vaps(char *fn, struct vap_tree *tree, struct aspa *aspa, * insert them in the right place in v->providers while keeping the * order of the providers array. */ - for (i = 0, j = 0; i < aspa->providersz; ) { - if (j == v->providersz || + for (i = 0, j = 0; i < aspa->num_providers; ) { + if (j == v->num_providers || aspa->providers[i] < v->providers[j]) { /* merge provider from aspa into v */ repo_stat_inc(rp, v->talid, RTYPE_ASPA, @@ -385,15 +385,15 @@ aspa_insert_vaps(char *fn, struct vap_tree *tree, struct aspa *aspa, } else if (aspa->providers[i] == v->providers[j]) i++; - if (j < v->providersz) + if (j < v->num_providers) j++; } - if (v->providersz >= MAX_ASPA_PROVIDERS) { + if (v->num_providers >= MAX_ASPA_PROVIDERS) { v->overflowed = 1; free(v->providers); v->providers = NULL; - v->providersz = 0; + v->num_providers = 0; repo_stat_inc(rp, v->talid, RTYPE_ASPA, STYPE_OVERFLOW); warnx("%s: too many providers for ASPA Customer ASID %u " "(more than %d)", fn, v->custasid, MAX_ASPA_PROVIDERS); diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 56637881514..fd31636f4c2 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.230 2024/11/12 09:23:07 tb Exp $ */ +/* $OpenBSD: extern.h,v 1.231 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -151,7 +151,7 @@ struct cert { */ struct tal { char **uri; /* well-formed rsync URIs */ - size_t urisz; /* number of URIs */ + size_t num_uris; unsigned char *pkey; /* DER-encoded public key */ size_t pkeysz; /* length of pkey */ char *descr; /* basename of tal file */ @@ -271,7 +271,7 @@ struct rsc { struct cert_as *ases; /* AS resources */ size_t num_ases; struct rscfile *files; /* FileAndHashes in the RSC */ - size_t filesz; /* number of FileAndHashes */ + size_t num_files; char *aia; /* AIA */ char *aki; /* AKI */ char *ski; /* SKI */ @@ -295,8 +295,8 @@ struct spl_pfx { */ struct spl { uint32_t asid; - struct spl_pfx *pfxs; - size_t pfxsz; + struct spl_pfx *prefixes; + size_t num_prefixes; int talid; char *aia; char *aki; @@ -314,9 +314,9 @@ struct spl { */ struct takey { char **comments; /* Comments */ - size_t commentsz; /* number of Comments */ + size_t num_comments; char **uris; /* CertificateURI */ - size_t urisz; /* number of CertificateURIs */ + size_t num_uris; unsigned char *pubkey; /* DER encoded SubjectPublicKeyInfo */ size_t pubkeysz; char *ski; /* hex encoded SubjectKeyIdentifier of pubkey */ @@ -392,7 +392,7 @@ struct aspa { char *ski; /* SKI */ uint32_t custasid; /* the customerASID */ uint32_t *providers; /* the providers */ - size_t providersz; /* number of providers */ + size_t num_providers; time_t signtime; /* CMS signing-time attribute */ time_t notbefore; /* EE cert's Not Before */ time_t notafter; /* notAfter of the ASPA EE cert */ @@ -407,7 +407,7 @@ struct vap { RB_ENTRY(vap) entry; uint32_t custasid; uint32_t *providers; - size_t providersz; + size_t num_providers; time_t expires; int talid; unsigned int repoid; @@ -448,7 +448,7 @@ struct vsp { RB_ENTRY(vsp) entry; uint32_t asid; struct spl_pfx *prefixes; - size_t prefixesz; + size_t num_prefixes; time_t expires; int talid; unsigned int repoid; diff --git a/usr.sbin/rpki-client/filemode.c b/usr.sbin/rpki-client/filemode.c index 997d26416d4..68527b26c11 100644 --- a/usr.sbin/rpki-client/filemode.c +++ b/usr.sbin/rpki-client/filemode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filemode.c,v 1.51 2024/11/05 06:05:35 tb Exp $ */ +/* $OpenBSD: filemode.c,v 1.52 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -269,7 +269,7 @@ parse_load_ta(struct tal *tal) cert->talid = tal->id; auth_insert(file, &auths, cert, NULL); - for (i = 0; i < tal->urisz; i++) { + for (i = 0; i < tal->num_uris; i++) { if (strncasecmp(tal->uri[i], RSYNC_PROTO, RSYNC_PROTO_LEN) != 0) continue; /* Add all rsync uri since any of them could be used as AIA. */ diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 05683d16f00..c74bb69642e 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.269 2024/11/02 12:30:28 job Exp $ */ +/* $OpenBSD: main.c,v 1.270 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -460,7 +460,7 @@ queue_add_from_tal(struct tal *tal) unsigned char *data; char *nfile; - assert(tal->urisz); + assert(tal->num_uris > 0); if ((taldescs[tal->id] = strdup(tal->descr)) == NULL) err(1, NULL); diff --git a/usr.sbin/rpki-client/output-bgpd.c b/usr.sbin/rpki-client/output-bgpd.c index fc6af38a417..cb8da58cde8 100644 --- a/usr.sbin/rpki-client/output-bgpd.c +++ b/usr.sbin/rpki-client/output-bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-bgpd.c,v 1.31 2024/04/08 14:02:13 tb Exp $ */ +/* $OpenBSD: output-bgpd.c,v 1.32 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -64,10 +64,10 @@ output_bgpd(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, "provider-as { ", vap->custasid, (long long)vap->expires) < 0) return -1; - for (i = 0; i < vap->providersz; i++) { + for (i = 0; i < vap->num_providers; i++) { if (fprintf(out, "%u", vap->providers[i]) < 0) return -1; - if (i + 1 < vap->providersz) + if (i + 1 < vap->num_providers) if (fprintf(out, ", ") < 0) return -1; } diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index d69d95f4c03..8c902a0f2cb 100644 --- a/usr.sbin/rpki-client/output-json.c +++ b/usr.sbin/rpki-client/output-json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-json.c,v 1.50 2024/09/03 15:04:48 job Exp $ */ +/* $OpenBSD: output-json.c,v 1.51 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * @@ -101,7 +101,7 @@ print_vap(struct vap *v) json_do_int("expires", v->expires); json_do_array("providers"); - for (i = 0; i < v->providersz; i++) + for (i = 0; i < v->num_providers; i++) json_do_int("provider", v->providers[i]); json_do_end(); @@ -130,7 +130,7 @@ output_spl(struct vsp_tree *vsps) json_do_object("vsp", 1); json_do_int("origin_as", vsp->asid); json_do_array("prefixes"); - for (i = 0; i < vsp->prefixesz; i++) { + for (i = 0; i < vsp->num_prefixes; i++) { ip_addr_print(&vsp->prefixes[i].prefix, vsp->prefixes[i].afi, buf, sizeof(buf)); json_do_string("prefix", buf); diff --git a/usr.sbin/rpki-client/print.c b/usr.sbin/rpki-client/print.c index 9ce73d081aa..830edf646c6 100644 --- a/usr.sbin/rpki-client/print.c +++ b/usr.sbin/rpki-client/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.57 2024/11/12 09:23:07 tb Exp $ */ +/* $OpenBSD: print.c,v 1.58 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -118,14 +118,14 @@ tal_print(const struct tal *p) json_do_string("name", p->descr); json_do_string("ski", pretty_key_id(ski)); json_do_array("trust_anchor_locations"); - for (i = 0; i < p->urisz; i++) + for (i = 0; i < p->num_uris; i++) json_do_string("tal", p->uri[i]); json_do_end(); } else { printf("Trust anchor name: %s\n", p->descr); printf("Subject key identifier: %s\n", pretty_key_id(ski)); printf("Trust anchor locations: "); - for (i = 0; i < p->urisz; i++) { + for (i = 0; i < p->num_uris; i++) { if (i > 0) printf("%26s", ""); printf("%s\n", p->uri[i]); @@ -600,8 +600,8 @@ spl_print(const X509 *x, const struct spl *s) if (outformats & FORMAT_JSON) json_do_array("prefixes"); - for (i = 0; i < s->pfxsz; i++) { - ip_addr_print(&s->pfxs[i].prefix, s->pfxs[i].afi, buf, + for (i = 0; i < s->num_prefixes; i++) { + ip_addr_print(&s->prefixes[i].prefix, s->prefixes[i].afi, buf, sizeof(buf)); if (outformats & FORMAT_JSON) { @@ -691,7 +691,7 @@ rsc_print(const X509 *x, const struct rsc *p) } else printf("Filenames and hashes: "); - for (i = 0; i < p->filesz; i++) { + for (i = 0; i < p->num_files; i++) { if (base64_encode(p->files[i].hash, sizeof(p->files[i].hash), &hash) == -1) errx(1, "base64_encode failure"); @@ -754,7 +754,7 @@ aspa_print(const X509 *x, const struct aspa *p) printf("Providers: "); } - for (i = 0; i < p->providersz; i++) { + for (i = 0; i < p->num_providers; i++) { if (outformats & FORMAT_JSON) json_do_uint("asid", p->providers[i]); else { @@ -781,11 +781,11 @@ takey_print(char *name, const struct takey *t) json_do_object("takey", 0); json_do_string("name", name); json_do_array("comments"); - for (i = 0; i < t->commentsz; i++) + for (i = 0; i < t->num_comments; i++) json_do_string("comment", t->comments[i]); json_do_end(); json_do_array("uris"); - for (i = 0; i < t->urisz; i++) + for (i = 0; i < t->num_uris; i++) json_do_string("uri", t->uris[i]); json_do_end(); json_do_string("spki", spki); @@ -793,11 +793,11 @@ takey_print(char *name, const struct takey *t) } else { printf("TAL derived from the '%s' Trust Anchor Key:\n\n", name); - for (i = 0; i < t->commentsz; i++) + for (i = 0; i < t->num_comments; i++) printf("\t# %s\n", t->comments[i]); - if (t->commentsz > 0) + if (t->num_comments > 0) printf("\n"); - for (i = 0; i < t->urisz; i++) + for (i = 0; i < t->num_uris; i++) printf("\t%s\n", t->uris[i]); printf("\n\t"); for (i = 0; i < strlen(spki); i++) { diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index ce322ed9545..4c5e6ee6e1d 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.69 2024/11/02 12:30:28 job Exp $ */ +/* $OpenBSD: repo.c,v 1.70 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -80,7 +80,7 @@ struct tarepo { char *descr; char *basedir; char **uri; - size_t urisz; + size_t num_uris; size_t uriidx; unsigned int id; enum repo_state state; @@ -356,14 +356,14 @@ static void ta_fetch(struct tarepo *tr) { if (!rrdpon) { - for (; tr->uriidx < tr->urisz; tr->uriidx++) { + for (; tr->uriidx < tr->num_uris; tr->uriidx++) { if (strncasecmp(tr->uri[tr->uriidx], RSYNC_PROTO, RSYNC_PROTO_LEN) == 0) break; } } - if (tr->uriidx >= tr->urisz) { + if (tr->uriidx >= tr->num_uris) { tr->state = REPO_FAILED; logx("ta/%s: fallback to cache", tr->descr); @@ -426,9 +426,9 @@ ta_get(struct tal *tal) } /* steal URI information from TAL */ - tr->urisz = tal->urisz; + tr->num_uris = tal->num_uris; tr->uri = tal->uri; - tal->urisz = 0; + tal->num_uris = 0; tal->uri = NULL; ta_fetch(tr); @@ -1150,7 +1150,7 @@ ta_lookup(int id, struct tal *tal) { struct repo *rp; - if (tal->urisz == 0) + if (tal->num_uris == 0) errx(1, "TAL %s has no URI", tal->descr); /* Look up in repository table. (Lookup should actually fail here) */ @@ -1358,7 +1358,7 @@ repo_proto(const struct repo *rp) if (rp->ta != NULL) { const struct tarepo *tr = rp->ta; - if (tr->uriidx < tr->urisz && + if (tr->uriidx < tr->num_uris && strncasecmp(tr->uri[tr->uriidx], RSYNC_PROTO, RSYNC_PROTO_LEN) == 0) return "rsync"; diff --git a/usr.sbin/rpki-client/rsc.c b/usr.sbin/rpki-client/rsc.c index 246a3bcfb75..11d657fdf5f 100644 --- a/usr.sbin/rpki-client/rsc.c +++ b/usr.sbin/rpki-client/rsc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsc.c,v 1.36 2024/11/12 09:23:07 tb Exp $ */ +/* $OpenBSD: rsc.c,v 1.37 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> * Copyright (c) 2022 Job Snijders <job@fastly.com> @@ -272,25 +272,25 @@ rsc_parse_checklist(const char *fn, struct rsc *rsc, FileNameAndHash *fh; ASN1_IA5STRING *fileName; struct rscfile *file; - size_t sz, i; + size_t num_files, i; - if ((sz = sk_FileNameAndHash_num(checkList)) == 0) { + if ((num_files = sk_FileNameAndHash_num(checkList)) == 0) { warnx("%s: RSC checkList needs at least one entry", fn); return 0; } - if (sz >= MAX_CHECKLIST_ENTRIES) { - warnx("%s: %zu exceeds checklist entry limit (%d)", fn, sz, - MAX_CHECKLIST_ENTRIES); + if (num_files >= MAX_CHECKLIST_ENTRIES) { + warnx("%s: %zu exceeds checklist entry limit (%d)", fn, + num_files, MAX_CHECKLIST_ENTRIES); return 0; } - rsc->files = calloc(sz, sizeof(struct rscfile)); + rsc->files = calloc(num_files, sizeof(struct rscfile)); if (rsc->files == NULL) err(1, NULL); - rsc->filesz = sz; + rsc->num_files = num_files; - for (i = 0; i < sz; i++) { + for (i = 0; i < num_files; i++) { fh = sk_FileNameAndHash_value(checkList, i); file = &rsc->files[i]; @@ -458,7 +458,7 @@ rsc_free(struct rsc *p) if (p == NULL) return; - for (i = 0; i < p->filesz; i++) + for (i = 0; i < p->num_files; i++) free(p->files[i].filename); free(p->aia); diff --git a/usr.sbin/rpki-client/spl.c b/usr.sbin/rpki-client/spl.c index d9642b353e8..16c8cf6cdf0 100644 --- a/usr.sbin/rpki-client/spl.c +++ b/usr.sbin/rpki-client/spl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spl.c,v 1.6 2024/11/12 09:23:07 tb Exp $ */ +/* $OpenBSD: spl.c,v 1.7 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2024 Job Snijders <job@fastly.com> * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> @@ -133,7 +133,7 @@ spl_parse_econtent(const char *fn, struct spl *spl, const unsigned char *d, const AddressFamilyPrefixes *afp; const STACK_OF(ASN1_BIT_STRING) *prefixes; const ASN1_BIT_STRING *prefix_asn1; - int afpsz, prefixesz; + int num_afps, num_prefixes; enum afi afi; struct ip_addr ip_addr; struct spl_pfx *prefix; @@ -160,25 +160,25 @@ spl_parse_econtent(const char *fn, struct spl *spl, const unsigned char *d, goto out; } - afpsz = sk_AddressFamilyPrefixes_num(spl_asn1->prefixBlocks); - if (afpsz < 0 || afpsz > 2) { + num_afps = sk_AddressFamilyPrefixes_num(spl_asn1->prefixBlocks); + if (num_afps < 0 || num_afps > 2) { warnx("%s: unexpected number of AddressFamilyAddressPrefixes" - "(got %d, expected 0, 1, or 2)", fn, afpsz); + "(got %d, expected 0, 1, or 2)", fn, num_afps); goto out; } - for (i = 0; i < afpsz; i++) { + for (i = 0; i < num_afps; i++) { struct ip_addr *prev_ip_addr = NULL; afp = sk_AddressFamilyPrefixes_value(spl_asn1->prefixBlocks, i); prefixes = afp->addressPrefixes; - prefixesz = sk_ASN1_BIT_STRING_num(afp->addressPrefixes); + num_prefixes = sk_ASN1_BIT_STRING_num(afp->addressPrefixes); - if (prefixesz == 0) { + if (num_prefixes == 0) { warnx("%s: empty AddressFamilyAddressPrefixes", fn); goto out; } - if (spl->pfxsz + prefixesz >= MAX_IP_SIZE) { + if (spl->num_prefixes + num_prefixes >= MAX_IP_SIZE) { warnx("%s: too many addressPrefixes entries", fn); goto out; } @@ -207,12 +207,12 @@ spl_parse_econtent(const char *fn, struct spl *spl, const unsigned char *d, } } - spl->pfxs = recallocarray(spl->pfxs, spl->pfxsz, - spl->pfxsz + prefixesz, sizeof(struct spl_pfx)); - if (spl->pfxs == NULL) + spl->prefixes = recallocarray(spl->prefixes, spl->num_prefixes, + spl->num_prefixes + num_prefixes, sizeof(spl->prefixes[0])); + if (spl->prefixes == NULL) err(1, NULL); - for (j = 0; j < prefixesz; j++) { + for (j = 0; j < num_prefixes; j++) { prefix_asn1 = sk_ASN1_BIT_STRING_value(prefixes, j); if (!ip_addr_parse(prefix_asn1, afi, fn, &ip_addr)) @@ -224,7 +224,7 @@ spl_parse_econtent(const char *fn, struct spl *spl, const unsigned char *d, goto out; } - prefix = &spl->pfxs[spl->pfxsz++]; + prefix = &spl->prefixes[spl->num_prefixes++]; prefix->prefix = ip_addr; prefix->afi = afi; prev_ip_addr = &prefix->prefix; @@ -330,7 +330,7 @@ spl_free(struct spl *s) free(s->aki); free(s->sia); free(s->ski); - free(s->pfxs); + free(s->prefixes); free(s); } @@ -344,10 +344,11 @@ spl_buffer(struct ibuf *b, const struct spl *s) io_simple_buffer(b, &s->valid, sizeof(s->valid)); io_simple_buffer(b, &s->asid, sizeof(s->asid)); io_simple_buffer(b, &s->talid, sizeof(s->talid)); - io_simple_buffer(b, &s->pfxsz, sizeof(s->pfxsz)); + io_simple_buffer(b, &s->num_prefixes, sizeof(s->num_prefixes)); io_simple_buffer(b, &s->expires, sizeof(s->expires)); - io_simple_buffer(b, s->pfxs, s->pfxsz * sizeof(s->pfxs[0])); + io_simple_buffer(b, s->prefixes, + s->num_prefixes * sizeof(s->prefixes[0])); io_str_buffer(b, s->aia); io_str_buffer(b, s->aki); @@ -370,13 +371,15 @@ spl_read(struct ibuf *b) io_read_buf(b, &s->valid, sizeof(s->valid)); io_read_buf(b, &s->asid, sizeof(s->asid)); io_read_buf(b, &s->talid, sizeof(s->talid)); - io_read_buf(b, &s->pfxsz, sizeof(s->pfxsz)); + io_read_buf(b, &s->num_prefixes, sizeof(s->num_prefixes)); io_read_buf(b, &s->expires, sizeof(s->expires)); - if (s->pfxsz > 0) { - if ((s->pfxs = calloc(s->pfxsz, sizeof(s->pfxs[0]))) == NULL) + if (s->num_prefixes > 0) { + if ((s->prefixes = calloc(s->num_prefixes, + sizeof(s->prefixes[0]))) == NULL) err(1, NULL); - io_read_buf(b, s->pfxs, s->pfxsz * sizeof(s->pfxs[0])); + io_read_buf(b, s->prefixes, + s->num_prefixes * sizeof(s->prefixes[0])); } io_read_str(b, &s->aia); @@ -401,11 +404,11 @@ spl_pfx_cmp(const struct spl_pfx *a, const struct spl_pfx *b) static void insert_vsp(struct vsp *vsp, size_t idx, struct spl_pfx *pfx) { - if (idx < vsp->prefixesz) + if (idx < vsp->num_prefixes) memmove(vsp->prefixes + idx + 1, vsp->prefixes + idx, - (vsp->prefixesz - idx) * sizeof(*vsp->prefixes)); + (vsp->num_prefixes - idx) * sizeof(vsp->prefixes[0])); vsp->prefixes[idx] = *pfx; - vsp->prefixesz++; + vsp->num_prefixes++; } /* @@ -449,7 +452,7 @@ spl_insert_vsps(struct vsp_tree *tree, struct spl *spl, struct repo *rp) /* merge content of multiple SPLs */ vsp->prefixes = reallocarray(vsp->prefixes, - vsp->prefixesz + spl->pfxsz, sizeof(struct spl_pfx)); + vsp->num_prefixes + spl->num_prefixes, sizeof(vsp->prefixes[0])); if (vsp->prefixes == NULL) err(1, NULL); @@ -458,16 +461,17 @@ spl_insert_vsps(struct vsp_tree *tree, struct spl *spl, struct repo *rp) * all SPL->pfxs, and insert them in the right place in * vsp->prefixes while keeping the order of the array. */ - for (i = 0, j = 0; i < spl->pfxsz; ) { + for (i = 0, j = 0; i < spl->num_prefixes; ) { cmp = -1; - if (j == vsp->prefixesz || - (cmp = spl_pfx_cmp(&spl->pfxs[i], &vsp->prefixes[j])) < 0) { - insert_vsp(vsp, j, &spl->pfxs[i]); + if (j == vsp->num_prefixes || + (cmp = spl_pfx_cmp(&spl->prefixes[i], + &vsp->prefixes[j])) < 0) { + insert_vsp(vsp, j, &spl->prefixes[i]); i++; } else if (cmp == 0) i++; - if (j < vsp->prefixesz) + if (j < vsp->num_prefixes) j++; } } diff --git a/usr.sbin/rpki-client/tak.c b/usr.sbin/rpki-client/tak.c index c497f7f58c2..dc40231fcfb 100644 --- a/usr.sbin/rpki-client/tak.c +++ b/usr.sbin/rpki-client/tak.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tak.c,v 1.20 2024/05/15 09:01:36 tb Exp $ */ +/* $OpenBSD: tak.c,v 1.21 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2022 Job Snijders <job@fastly.com> * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> @@ -94,29 +94,30 @@ parse_takey(const char *fn, const TAKey *takey) if ((res = calloc(1, sizeof(struct takey))) == NULL) err(1, NULL); - res->commentsz = sk_ASN1_UTF8STRING_num(takey->comments); - if (res->commentsz > 0) { - res->comments = calloc(res->commentsz, sizeof(char *)); + res->num_comments = sk_ASN1_UTF8STRING_num(takey->comments); + if (res->num_comments > 0) { + res->comments = calloc(res->num_comments, sizeof(char *)); if (res->comments == NULL) err(1, NULL); - for (i = 0; i < res->commentsz; i++) { + for (i = 0; i < res->num_comments; i++) { comment = sk_ASN1_UTF8STRING_value(takey->comments, i); - res->comments[i] = strndup(comment->data, comment->length); + res->comments[i] = strndup(comment->data, + comment->length); if (res->comments[i] == NULL) err(1, NULL); } } - res->urisz = sk_ASN1_IA5STRING_num(takey->certificateURIs); - if (res->urisz == 0) { + res->num_uris = sk_ASN1_IA5STRING_num(takey->certificateURIs); + if (res->num_uris == 0) { warnx("%s: Signed TAL requires at least 1 CertificateURI", fn); goto err; } - if ((res->uris = calloc(res->urisz, sizeof(char *))) == NULL) + if ((res->uris = calloc(res->num_uris, sizeof(char *))) == NULL) err(1, NULL); - for (i = 0; i < res->urisz; i++) { + for (i = 0; i < res->num_uris; i++) { certURI = sk_ASN1_IA5STRING_value(takey->certificateURIs, i); if (!valid_uri(certURI->data, certURI->length, NULL)) { warnx("%s: invalid TA URI", fn); @@ -279,10 +280,10 @@ takey_free(struct takey *t) if (t == NULL) return; - for (i = 0; i < t->commentsz; i++) + for (i = 0; i < t->num_comments; i++) free(t->comments[i]); - for (i = 0; i < t->urisz; i++) + for (i = 0; i < t->num_uris; i++) free(t->uris[i]); free(t->comments); diff --git a/usr.sbin/rpki-client/tal.c b/usr.sbin/rpki-client/tal.c index d8f475c1a71..8cc926844d2 100644 --- a/usr.sbin/rpki-client/tal.c +++ b/usr.sbin/rpki-client/tal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tal.c,v 1.40 2024/03/22 03:38:12 job Exp $ */ +/* $OpenBSD: tal.c,v 1.41 2024/11/13 12:51:04 tb Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -96,14 +96,14 @@ tal_parse_buffer(const char *fn, char *buf, size_t len) /* Append to list of URIs. */ tal->uri = reallocarray(tal->uri, - tal->urisz + 1, sizeof(char *)); + tal->num_uris + 1, sizeof(char *)); if (tal->uri == NULL) err(1, NULL); - tal->uri[tal->urisz] = strdup(line); - if (tal->uri[tal->urisz] == NULL) + tal->uri[tal->num_uris] = strdup(line); + if (tal->uri[tal->num_uris] == NULL) err(1, NULL); - tal->urisz++; + tal->num_uris++; f = strrchr(line, '/') + 1; /* can not fail */ if (file) { @@ -116,13 +116,13 @@ tal_parse_buffer(const char *fn, char *buf, size_t len) file = f; } - if (tal->urisz == 0) { + if (tal->num_uris == 0) { warnx("%s: no URIs in TAL file", fn); goto out; } /* sort uri lexicographically so https:// is preferred */ - qsort(tal->uri, tal->urisz, sizeof(tal->uri[0]), tal_cmp); + qsort(tal->uri, tal->num_uris, sizeof(tal->uri[0]), tal_cmp); /* Now the Base64-encoded public key. */ if ((base64_decode(buf, len, &der, &dersz)) == -1) { @@ -195,7 +195,7 @@ tal_free(struct tal *p) return; if (p->uri != NULL) - for (i = 0; i < p->urisz; i++) + for (i = 0; i < p->num_uris; i++) free(p->uri[i]); free(p->pkey); @@ -216,9 +216,9 @@ tal_buffer(struct ibuf *b, const struct tal *p) io_simple_buffer(b, &p->id, sizeof(p->id)); io_buf_buffer(b, p->pkey, p->pkeysz); io_str_buffer(b, p->descr); - io_simple_buffer(b, &p->urisz, sizeof(p->urisz)); + io_simple_buffer(b, &p->num_uris, sizeof(p->num_uris)); - for (i = 0; i < p->urisz; i++) + for (i = 0; i < p->num_uris; i++) io_str_buffer(b, p->uri[i]); } @@ -239,15 +239,15 @@ tal_read(struct ibuf *b) io_read_buf(b, &p->id, sizeof(p->id)); io_read_buf_alloc(b, (void **)&p->pkey, &p->pkeysz); io_read_str(b, &p->descr); - io_read_buf(b, &p->urisz, sizeof(p->urisz)); + io_read_buf(b, &p->num_uris, sizeof(p->num_uris)); assert(p->pkeysz > 0); assert(p->descr); - assert(p->urisz > 0); + assert(p->num_uris > 0); - if ((p->uri = calloc(p->urisz, sizeof(char *))) == NULL) + if ((p->uri = calloc(p->num_uris, sizeof(char *))) == NULL) err(1, NULL); - for (i = 0; i < p->urisz; i++) { + for (i = 0; i < p->num_uris; i++) { io_read_str(b, &p->uri[i]); assert(p->uri[i]); } |