diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-12-21 11:35:56 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-12-21 11:35:56 +0000 |
commit | 0fea1445927afbb614bcce94154ec4f16c3a6290 (patch) | |
tree | 950e9b8196b8fb8163aaf7a72a7ded1298f24226 /usr.sbin | |
parent | 1d1f47626e3ee6434fec9f1897ef0428d97e2a4a (diff) |
Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rpki-client/cert.c | 25 | ||||
-rw-r--r-- | usr.sbin/rpki-client/main.c | 14 | ||||
-rw-r--r-- | usr.sbin/rpki-client/mft.c | 5 | ||||
-rw-r--r-- | usr.sbin/rpki-client/roa.c | 4 | ||||
-rw-r--r-- | usr.sbin/rpki-client/rsync.c | 4 | ||||
-rw-r--r-- | usr.sbin/rpki-client/tal.c | 7 |
6 files changed, 26 insertions, 33 deletions
diff --git a/usr.sbin/rpki-client/cert.c b/usr.sbin/rpki-client/cert.c index 50bf59ee6ee..3023c5a25c7 100644 --- a/usr.sbin/rpki-client/cert.c +++ b/usr.sbin/rpki-client/cert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cert.c,v 1.20 2020/12/07 13:23:01 claudio Exp $ */ +/* $OpenBSD: cert.c,v 1.21 2020/12/21 11:35:55 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -1262,7 +1262,6 @@ void cert_buffer(char **b, size_t *bsz, size_t *bmax, const struct cert *p) { size_t i; - int has_crl, has_aki; io_simple_buffer(b, bsz, bmax, &p->valid, sizeof(int)); io_simple_buffer(b, bsz, bmax, &p->ipsz, sizeof(size_t)); @@ -1275,15 +1274,8 @@ cert_buffer(char **b, size_t *bsz, size_t *bmax, const struct cert *p) io_str_buffer(b, bsz, bmax, p->mft); io_str_buffer(b, bsz, bmax, p->notify); - - has_crl = (p->crl != NULL); - io_simple_buffer(b, bsz, bmax, &has_crl, sizeof(int)); - if (has_crl) - io_str_buffer(b, bsz, bmax, p->crl); - has_aki = (p->aki != NULL); - io_simple_buffer(b, bsz, bmax, &has_aki, sizeof(int)); - if (has_aki) - io_str_buffer(b, bsz, bmax, p->aki); + io_str_buffer(b, bsz, bmax, p->crl); + io_str_buffer(b, bsz, bmax, p->aki); io_str_buffer(b, bsz, bmax, p->ski); } @@ -1327,7 +1319,6 @@ cert_read(int fd) { struct cert *p; size_t i; - int has_crl, has_aki; if ((p = calloc(1, sizeof(struct cert))) == NULL) err(1, NULL); @@ -1348,14 +1339,12 @@ cert_read(int fd) cert_as_read(fd, &p->as[i]); io_str_read(fd, &p->mft); + assert(p->mft); io_str_read(fd, &p->notify); - io_simple_read(fd, &has_crl, sizeof(int)); - if (has_crl) - io_str_read(fd, &p->crl); - io_simple_read(fd, &has_aki, sizeof(int)); - if (has_aki) - io_str_read(fd, &p->aki); + io_str_read(fd, &p->crl); + io_str_read(fd, &p->aki); io_str_read(fd, &p->ski); + assert(p->ski); return p; } diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index e433cac7a16..d1ad28fa925 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.87 2020/12/18 12:31:06 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.88 2020/12/21 11:35:55 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -114,7 +114,6 @@ struct entity { int has_pkey; /* whether pkey/sz is specified */ unsigned char *pkey; /* public key (optional) */ size_t pkeysz; /* public key length (optional) */ - int has_descr; /* whether descr is specified */ char *descr; /* tal description */ TAILQ_ENTRY(entity) entries; }; @@ -233,9 +232,7 @@ entity_read_req(int fd, struct entity *ent) io_simple_read(fd, &ent->has_pkey, sizeof(int)); if (ent->has_pkey) io_buf_read_alloc(fd, (void **)&ent->pkey, &ent->pkeysz); - io_simple_read(fd, &ent->has_descr, sizeof(int)); - if (ent->has_descr) - io_str_read(fd, &ent->descr); + io_str_read(fd, &ent->descr); } /* @@ -256,9 +253,7 @@ entity_buffer_req(char **b, size_t *bsz, size_t *bmax, io_simple_buffer(b, bsz, bmax, &ent->has_pkey, sizeof(int)); if (ent->has_pkey) io_buf_buffer(b, bsz, bmax, ent->pkey, ent->pkeysz); - io_simple_buffer(b, bsz, bmax, &ent->has_descr, sizeof(int)); - if (ent->has_descr) - io_str_buffer(b, bsz, bmax, ent->descr); + io_str_buffer(b, bsz, bmax, ent->descr); } /* @@ -418,7 +413,6 @@ entityq_add(int fd, struct entityq *q, char *file, enum rtype type, p->repo = (rp != NULL) ? (ssize_t)rp->id : -1; p->has_dgst = dgst != NULL; p->has_pkey = pkey != NULL; - p->has_descr = descr != NULL; if (p->has_dgst) memcpy(p->dgst, dgst, sizeof(p->dgst)); if (p->has_pkey) { @@ -427,7 +421,7 @@ entityq_add(int fd, struct entityq *q, char *file, enum rtype type, err(1, "malloc"); memcpy(p->pkey, pkey, pkeysz); } - if (p->has_descr) + if (descr != NULL) if ((p->descr = strdup(descr)) == NULL) err(1, "strdup"); diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index c8eed812942..3b0d06635a4 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.21 2020/12/18 12:31:06 claudio Exp $ */ +/* $OpenBSD: mft.c,v 1.22 2020/12/21 11:35:55 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -552,6 +552,7 @@ mft_read(int fd) io_simple_read(fd, &p->stale, sizeof(int)); io_str_read(fd, &p->file); + assert(p->file); io_simple_read(fd, &p->filesz, sizeof(size_t)); if ((p->files = calloc(p->filesz, sizeof(struct mftfile))) == NULL) @@ -564,5 +565,7 @@ mft_read(int fd) io_str_read(fd, &p->aki); io_str_read(fd, &p->ski); + assert(p->aki && p->ski); + return p; } diff --git a/usr.sbin/rpki-client/roa.c b/usr.sbin/rpki-client/roa.c index 8d73bc9fb37..b6044d13681 100644 --- a/usr.sbin/rpki-client/roa.c +++ b/usr.sbin/rpki-client/roa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roa.c,v 1.9 2020/09/12 15:46:48 claudio Exp $ */ +/* $OpenBSD: roa.c,v 1.10 2020/12/21 11:35:55 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -445,6 +445,8 @@ roa_read(int fd) io_str_read(fd, &p->aki); io_str_read(fd, &p->ski); io_str_read(fd, &p->tal); + assert(p->aki && p->ski && p->tal); + return p; } diff --git a/usr.sbin/rpki-client/rsync.c b/usr.sbin/rpki-client/rsync.c index a21b8653b4e..5d4bee0e98e 100644 --- a/usr.sbin/rpki-client/rsync.c +++ b/usr.sbin/rpki-client/rsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsync.c,v 1.11 2020/12/02 15:31:15 claudio Exp $ */ +/* $OpenBSD: rsync.c,v 1.12 2020/12/21 11:35:55 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -296,6 +296,8 @@ proc_rsync(char *prog, char *bind_addr, int fd) io_str_read(fd, &host); io_str_read(fd, &mod); + assert(host); + assert(mod); /* * Create source and destination locations. diff --git a/usr.sbin/rpki-client/tal.c b/usr.sbin/rpki-client/tal.c index dc2077dd866..f3db5d4f2eb 100644 --- a/usr.sbin/rpki-client/tal.c +++ b/usr.sbin/rpki-client/tal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tal.c,v 1.24 2020/12/03 15:02:12 claudio Exp $ */ +/* $OpenBSD: tal.c,v 1.25 2020/12/21 11:35:55 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -330,14 +330,17 @@ tal_read(int fd) io_buf_read_alloc(fd, (void **)&p->pkey, &p->pkeysz); assert(p->pkeysz > 0); io_str_read(fd, &p->descr); + assert(p->descr); io_simple_read(fd, &p->urisz, sizeof(size_t)); assert(p->urisz > 0); if ((p->uri = calloc(p->urisz, sizeof(char *))) == NULL) err(1, NULL); - for (i = 0; i < p->urisz; i++) + for (i = 0; i < p->urisz; i++) { io_str_read(fd, &p->uri[i]); + assert(p->uri[i]); + } return p; } |