From b6884e9f8f78d443baefdc010ef8ac72b89f167d Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 22 Dec 2021 09:35:14 +0000 Subject: [PATCH] Replace two questionable size_t types. For the repo id use a unsigned int and for the roa maxlength use unsigned char (like the prefixlen in struct ip_addr). With input and OK job@ --- usr.sbin/rpki-client/extern.h | 24 +++++++++++------------ usr.sbin/rpki-client/http.c | 21 ++++++++++---------- usr.sbin/rpki-client/main.c | 25 ++++++++++++++---------- usr.sbin/rpki-client/print.c | 4 ++-- usr.sbin/rpki-client/repo.c | 36 +++++++++++++++++------------------ usr.sbin/rpki-client/rrdp.c | 24 +++++++++++------------ usr.sbin/rpki-client/rsync.c | 13 +++++++------ 7 files changed, 77 insertions(+), 70 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index bfee4fd0194..9a7dcf6ff42 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.98 2021/11/25 14:03:40 job Exp $ */ +/* $OpenBSD: extern.h,v 1.99 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -179,10 +179,10 @@ struct mft { */ struct roa_ip { enum afi afi; /* AFI value */ - size_t maxlength; /* max length or zero */ + struct ip_addr addr; /* the address prefix itself */ unsigned char min[16]; /* full range minimum */ unsigned char max[16]; /* full range maximum */ - struct ip_addr addr; /* the address prefix itself */ + unsigned char maxlength; /* max length or zero */ }; /* @@ -498,8 +498,8 @@ void proc_rrdp(int); /* Repository handling */ int filepath_add(struct filepath_tree *, char *); -void rrdp_save_state(size_t, struct rrdp_session *); -int rrdp_handle_file(size_t, enum publish_type, char *, +void rrdp_save_state(unsigned int, struct rrdp_session *); +int rrdp_handle_file(unsigned int, enum publish_type, char *, char *, size_t, char *, size_t); char *repo_filename(const struct repo *, const char *); struct repo *ta_lookup(int, struct tal *); @@ -508,15 +508,15 @@ int repo_queued(struct repo *, struct entity *); void repo_cleanup(struct filepath_tree *); void repo_free(void); -void rsync_finish(size_t, int); -void http_finish(size_t, enum http_result, const char *); -void rrdp_finish(size_t, int); +void rsync_finish(unsigned int, int); +void http_finish(unsigned int, enum http_result, const char *); +void rrdp_finish(unsigned int, int); -void rsync_fetch(size_t, const char *, const char *); -void http_fetch(size_t, const char *, const char *, int); -void rrdp_fetch(size_t, const char *, const char *, +void rsync_fetch(unsigned int, const char *, const char *); +void http_fetch(unsigned int, const char *, const char *, int); +void rrdp_fetch(unsigned int, const char *, const char *, struct rrdp_session *); -void rrdp_http_done(size_t, enum http_result, const char *); +void rrdp_http_done(unsigned int, enum http_result, const char *); int repo_next_timeout(int); void repo_check_timeout(void); diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index 4c3d9cb1fcd..20cbd3cd75f 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.50 2021/11/10 09:13:30 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.51 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -140,7 +140,7 @@ struct http_request { char *host; char *port; const char *path; /* points into uri */ - size_t id; + unsigned int id; int outfd; int redirect_loop; }; @@ -150,7 +150,7 @@ TAILQ_HEAD(http_req_queue, http_request); static struct http_conn_list active = LIST_HEAD_INITIALIZER(active); static struct http_conn_list idle = LIST_HEAD_INITIALIZER(idle); static struct http_req_queue queue = TAILQ_HEAD_INITIALIZER(queue); -static size_t http_conn_count; +static unsigned int http_conn_count; static struct msgbuf msgq; static struct sockaddr_storage http_bindaddr; @@ -159,10 +159,10 @@ static uint8_t *tls_ca_mem; static size_t tls_ca_size; /* HTTP request API */ -static void http_req_new(size_t, char *, char *, int, int); +static void http_req_new(unsigned int, char *, char *, int, int); static void http_req_free(struct http_request *); -static void http_req_done(size_t, enum http_result, const char *); -static void http_req_fail(size_t); +static void http_req_done(unsigned int, enum http_result, const char *); +static void http_req_fail(unsigned int); static int http_req_schedule(struct http_request *); /* HTTP connection API */ @@ -509,7 +509,8 @@ http_resolv(struct addrinfo **res, const char *host, const char *port) * Create and queue a new request. */ static void -http_req_new(size_t id, char *uri, char *modified_since, int count, int outfd) +http_req_new(unsigned int id, char *uri, char *modified_since, int count, + int outfd) { struct http_request *req; char *host, *port, *path; @@ -560,7 +561,7 @@ http_req_free(struct http_request *req) * Enqueue request response */ static void -http_req_done(size_t id, enum http_result res, const char *last_modified) +http_req_done(unsigned int id, enum http_result res, const char *last_modified) { struct ibuf *b; @@ -575,7 +576,7 @@ http_req_done(size_t id, enum http_result res, const char *last_modified) * Enqueue request failure response */ static void -http_req_fail(size_t id) +http_req_fail(unsigned int id) { struct ibuf *b; enum http_result res = HTTP_FAILED; @@ -1862,7 +1863,7 @@ proc_http(char *bind_addr, int fd) if (pfds[0].revents & POLLIN) { b = io_buf_recvfd(fd, &inbuf); if (b != NULL) { - size_t id; + unsigned int id; char *uri; char *mod; diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 8e96c7ac23b..a2f476c8d00 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.168 2021/12/21 17:50:27 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.169 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -228,7 +228,7 @@ entityq_add(char *file, enum rtype type, struct repo *rp, } static void -rrdp_file_resp(size_t id, int ok) +rrdp_file_resp(unsigned int id, int ok) { enum rrdp_msg type = RRDP_FILE; struct ibuf *b; @@ -241,7 +241,7 @@ rrdp_file_resp(size_t id, int ok) } void -rrdp_fetch(size_t id, const char *uri, const char *local, +rrdp_fetch(unsigned int id, const char *uri, const char *local, struct rrdp_session *s) { enum rrdp_msg type = RRDP_START; @@ -262,7 +262,7 @@ rrdp_fetch(size_t id, const char *uri, const char *local, * Request a repository sync via rsync URI to directory local. */ void -rsync_fetch(size_t id, const char *uri, const char *local) +rsync_fetch(unsigned int id, const char *uri, const char *local) { struct ibuf *b; @@ -277,7 +277,7 @@ rsync_fetch(size_t id, const char *uri, const char *local) * Request a file from a https uri, data is written to the file descriptor fd. */ void -http_fetch(size_t id, const char *uri, const char *last_mod, int fd) +http_fetch(unsigned int id, const char *uri, const char *last_mod, int fd) { struct ibuf *b; @@ -295,7 +295,7 @@ http_fetch(size_t id, const char *uri, const char *last_mod, int fd) * Create a pipe and pass the pipe endpoints to the http and rrdp process. */ static void -rrdp_http_fetch(size_t id, const char *uri, const char *last_mod) +rrdp_http_fetch(unsigned int id, const char *uri, const char *last_mod) { enum rrdp_msg type = RRDP_HTTP_INI; struct ibuf *b; @@ -314,7 +314,7 @@ rrdp_http_fetch(size_t id, const char *uri, const char *last_mod) } void -rrdp_http_done(size_t id, enum http_result res, const char *last_mod) +rrdp_http_done(unsigned int id, enum http_result res, const char *last_mod) { enum rrdp_msg type = RRDP_HTTP_FIN; struct ibuf *b; @@ -562,7 +562,8 @@ rrdp_process(struct ibuf *b) struct rrdp_session s; char *uri, *last_mod, *data; char hash[SHA256_DIGEST_LENGTH]; - size_t dsz, id; + size_t dsz; + unsigned int id; int ok; io_read_buf(b, &type, sizeof(type)); @@ -673,9 +674,9 @@ suicide(int sig __attribute__((unused))) int main(int argc, char *argv[]) { - int rc, c, st, proc, rsync, http, rrdp, ok, hangup = 0; + int rc, c, st, proc, rsync, http, rrdp, hangup = 0; int fl = SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK; - size_t i, id; + size_t i; pid_t pid, procpid, rsyncpid, httppid, rrdppid; int fd[2]; struct pollfd pfd[NPFD]; @@ -1068,6 +1069,9 @@ main(int argc, char *argv[]) if ((pfd[1].revents & POLLIN)) { b = io_buf_read(rsync, &rsyncbuf); if (b != NULL) { + unsigned int id; + int ok; + io_read_buf(b, &id, sizeof(id)); io_read_buf(b, &ok, sizeof(ok)); rsync_finish(id, ok); @@ -1078,6 +1082,7 @@ main(int argc, char *argv[]) if ((pfd[2].revents & POLLIN)) { b = io_buf_read(http, &httpbuf); if (b != NULL) { + unsigned int id; enum http_result res; char *last_mod; diff --git a/usr.sbin/rpki-client/print.c b/usr.sbin/rpki-client/print.c index addc4935cd8..e5fdfc1ac7a 100644 --- a/usr.sbin/rpki-client/print.c +++ b/usr.sbin/rpki-client/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.2 2021/10/25 14:07:56 claudio Exp $ */ +/* $OpenBSD: print.c,v 1.3 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -151,7 +151,7 @@ roa_print(const struct roa *p) for (i = 0; i < p->ipsz; i++) { ip_addr_print(&p->ips[i].addr, p->ips[i].afi, buf, sizeof(buf)); - printf("%5zu: %s maxlen: %zu\n", i + 1, + printf("%5zu: %s maxlen: %hhu\n", i + 1, buf, p->ips[i].maxlength); } } diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index a9badbfeab1..b05cd64f4b3 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.16 2021/12/21 16:16:15 claudio Exp $ */ +/* $OpenBSD: repo.c,v 1.17 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -61,7 +61,7 @@ struct rrdprepo { char *temp; struct filepath_tree added; struct filepath_tree deleted; - size_t id; + unsigned int id; enum repo_state state; }; SLIST_HEAD(, rrdprepo) rrdprepos = SLIST_HEAD_INITIALIZER(rrdprepos); @@ -70,7 +70,7 @@ struct rsyncrepo { SLIST_ENTRY(rsyncrepo) entry; char *repouri; char *basedir; - size_t id; + unsigned int id; enum repo_state state; }; SLIST_HEAD(, rsyncrepo) rsyncrepos = SLIST_HEAD_INITIALIZER(rsyncrepos); @@ -83,7 +83,7 @@ struct tarepo { char **uri; size_t urisz; size_t uriidx; - size_t id; + unsigned int id; enum repo_state state; }; SLIST_HEAD(, tarepo) tarepos = SLIST_HEAD_INITIALIZER(tarepos); @@ -98,12 +98,12 @@ struct repo { struct entityq queue; /* files waiting for repo */ time_t alarm; /* sync timeout */ int talid; - size_t id; /* identifier */ + unsigned int id; /* identifier */ }; SLIST_HEAD(, repo) repos = SLIST_HEAD_INITIALIZER(repos); /* counter for unique repo id */ -size_t repoid; +unsigned int repoid; /* * Database of all file path accessed during a run. @@ -421,7 +421,7 @@ ta_get(struct tal *tal) } static struct tarepo * -ta_find(size_t id) +ta_find(unsigned int id) { struct tarepo *tr; @@ -490,7 +490,7 @@ rsync_get(const char *uri, int nofetch) } static struct rsyncrepo * -rsync_find(size_t id) +rsync_find(unsigned int id) { struct rsyncrepo *rr; @@ -563,7 +563,7 @@ rrdp_get(const char *uri, int nofetch) } static struct rrdprepo * -rrdp_find(size_t id) +rrdp_find(unsigned int id) { struct rrdprepo *rr; @@ -710,7 +710,7 @@ fail: * Carefully write the RRDP session state file back. */ void -rrdp_save_state(size_t id, struct rrdp_session *state) +rrdp_save_state(unsigned int id, struct rrdp_session *state) { struct rrdprepo *rr; char *temp, *file; @@ -719,7 +719,7 @@ rrdp_save_state(size_t id, struct rrdp_session *state) rr = rrdp_find(id); if (rr == NULL) - errx(1, "non-existant rrdp repo %zu", id); + errx(1, "non-existant rrdp repo %u", id); file = rrdp_state_filename(rr, 0); temp = rrdp_state_filename(rr, 1); @@ -769,7 +769,7 @@ fail: * Returns 1 on success, 0 if the repo is corrupt, -1 on IO error */ int -rrdp_handle_file(size_t id, enum publish_type pt, char *uri, +rrdp_handle_file(unsigned int id, enum publish_type pt, char *uri, char *hash, size_t hlen, char *data, size_t dlen) { struct rrdprepo *rr; @@ -780,7 +780,7 @@ rrdp_handle_file(size_t id, enum publish_type pt, char *uri, rr = rrdp_find(id); if (rr == NULL) - errx(1, "non-existant rrdp repo %zu", id); + errx(1, "non-existant rrdp repo %u", id); if (rr->state == REPO_FAILED) return -1; @@ -929,7 +929,7 @@ rrdp_clean_temp(struct rrdprepo *rr) * RSYNC sync finished, either with or without success. */ void -rsync_finish(size_t id, int ok) +rsync_finish(unsigned int id, int ok) { struct rsyncrepo *rr; struct tarepo *tr; @@ -960,7 +960,7 @@ rsync_finish(size_t id, int ok) rr = rsync_find(id); if (rr == NULL) - errx(1, "unknown rsync repo %zu", id); + errx(1, "unknown rsync repo %u", id); /* repository changed state already, ignore request */ if (rr->state != REPO_LOADING) @@ -985,14 +985,14 @@ rsync_finish(size_t id, int ok) * RRDP sync finshed, either with or without success. */ void -rrdp_finish(size_t id, int ok) +rrdp_finish(unsigned int id, int ok) { struct rrdprepo *rr; struct repo *rp; rr = rrdp_find(id); if (rr == NULL) - errx(1, "unknown RRDP repo %zu", id); + errx(1, "unknown RRDP repo %u", id); /* repository changed state already, ignore request */ if (rr->state != REPO_LOADING) return; @@ -1035,7 +1035,7 @@ rrdp_finish(size_t id, int ok) * over to the rrdp process. */ void -http_finish(size_t id, enum http_result res, const char *last_mod) +http_finish(unsigned int id, enum http_result res, const char *last_mod) { struct tarepo *tr; struct repo *rp; diff --git a/usr.sbin/rpki-client/rrdp.c b/usr.sbin/rpki-client/rrdp.c index 67cc67d0823..3ee191f74d6 100644 --- a/usr.sbin/rpki-client/rrdp.c +++ b/usr.sbin/rpki-client/rrdp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rrdp.c,v 1.18 2021/11/24 15:24:16 claudio Exp $ */ +/* $OpenBSD: rrdp.c,v 1.19 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2021 Claudio Jeker @@ -49,7 +49,7 @@ static struct msgbuf msgq; struct rrdp { TAILQ_ENTRY(rrdp) entry; - size_t id; + unsigned int id; char *notifyuri; char *local; char *last_mod; @@ -89,7 +89,7 @@ xstrdup(const char *s) * ok should only be set to 1 if the cache is now up-to-date. */ static void -rrdp_done(size_t id, int ok) +rrdp_done(unsigned int id, int ok) { enum rrdp_msg type = RRDP_END; struct ibuf *b; @@ -110,7 +110,7 @@ rrdp_done(size_t id, int ok) * should be set to NULL, else it should point to a proper date string. */ static void -rrdp_http_req(size_t id, const char *uri, const char *last_mod) +rrdp_http_req(unsigned int id, const char *uri, const char *last_mod) { enum rrdp_msg type = RRDP_HTTP_REQ; struct ibuf *b; @@ -167,7 +167,7 @@ rrdp_publish_file(struct rrdp *s, struct publish_xml *pxml, } static struct rrdp * -rrdp_new(size_t id, char *local, char *notify, char *session_id, +rrdp_new(unsigned int id, char *local, char *notify, char *session_id, long long serial, char *last_mod) { struct rrdp *s; @@ -223,7 +223,7 @@ rrdp_free(struct rrdp *s) } static struct rrdp * -rrdp_get(size_t id) +rrdp_get(unsigned int id) { struct rrdp *s; @@ -236,7 +236,7 @@ rrdp_get(size_t id) static void rrdp_failed(struct rrdp *s) { - size_t id = s->id; + unsigned int id = s->id; /* reset file state before retrying */ s->file_failed = 0; @@ -264,7 +264,7 @@ rrdp_failed(struct rrdp *s) static void rrdp_finished(struct rrdp *s) { - size_t id = s->id; + unsigned int id = s->id; /* check if all parts of the process have finished */ if ((s->state & RRDP_STATE_DONE) != RRDP_STATE_DONE) @@ -365,7 +365,7 @@ rrdp_input_handler(int fd) enum rrdp_msg type; enum http_result res; long long serial; - size_t id; + unsigned int id; int ok; b = io_buf_recvfd(fd, &inbuf); @@ -392,7 +392,7 @@ rrdp_input_handler(int fd) errx(1, "expected fd not received"); s = rrdp_get(id); if (s == NULL) - errx(1, "rrdp session %zu does not exist", id); + errx(1, "rrdp session %u does not exist", id); if (s->state != RRDP_STATE_WAIT) errx(1, "%s: bad internal state", s->local); @@ -407,7 +407,7 @@ rrdp_input_handler(int fd) s = rrdp_get(id); if (s == NULL) - errx(1, "rrdp session %zu does not exist", id); + errx(1, "rrdp session %u does not exist", id); if (!(s->state & RRDP_STATE_PARSE)) errx(1, "%s: bad internal state", s->local); @@ -419,7 +419,7 @@ rrdp_input_handler(int fd) case RRDP_FILE: s = rrdp_get(id); if (s == NULL) - errx(1, "rrdp session %zu does not exist", id); + errx(1, "rrdp session %u does not exist", id); if (b->fd != -1) errx(1, "received unexpected fd"); io_read_buf(b, &ok, sizeof(ok)); diff --git a/usr.sbin/rpki-client/rsync.c b/usr.sbin/rpki-client/rsync.c index 14dbd26cc53..58d22764368 100644 --- a/usr.sbin/rpki-client/rsync.c +++ b/usr.sbin/rpki-client/rsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsync.c,v 1.30 2021/11/03 14:59:37 claudio Exp $ */ +/* $OpenBSD: rsync.c,v 1.31 2021/12/22 09:35:14 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -42,9 +42,9 @@ * of which process maps to which request. */ struct rsyncproc { - char *uri; /* uri of this rsync proc */ - size_t id; /* identity of request */ - pid_t pid; /* pid of process or 0 if unassociated */ + char *uri; /* uri of this rsync proc */ + unsigned int id; /* identity of request */ + pid_t pid; /* pid of process or 0 if unassociated */ }; /* @@ -182,7 +182,7 @@ proc_rsync(char *prog, char *bind_addr, int fd) for (;;) { char *uri = NULL, *dst = NULL; - size_t id; + unsigned int id; pid_t pid; int st; @@ -222,7 +222,8 @@ proc_rsync(char *prog, char *bind_addr, int fd) } b = io_new_buffer(); - io_simple_buffer(b, &ids[i].id, sizeof(size_t)); + io_simple_buffer(b, &ids[i].id, + sizeof(ids[i].id)); io_simple_buffer(b, &ok, sizeof(ok)); io_close_buffer(&msgq, b); -- 2.20.1