From: pcarana Date: Wed, 23 Sep 2020 17:02:45 +0000 (-0500) Subject: Fix leaks due to bad struct release and wrong lock usage X-Git-Tag: v1.4.1~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=75ff22f99eeba58652c09cda99f3d9c8b3c0a659;p=thirdparty%2FFORT-validator.git Fix leaks due to bad struct release and wrong lock usage +Also add missing parenthesis at logging docs, and fix lock usage at RRDP DB (db_rrdp_reset_visited_tals). --- diff --git a/docs/logging.md b/docs/logging.md index 8b28d5dc..bac5d34b 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -51,7 +51,7 @@ The following messages are included at the operation logs: - Out of memory errors. - Read/write errors on local files. - Persistent communication errors with RPKI repositories (see [`--stale-repository-period`](usage.html#--stale-repository-period)). -- Start and end of a validation cycle, including: number of valid Prefixes and Router Keys, current RTR serial number (only when [`--mode=server`](usage.html#--mode), and real execution time. +- Start and end of a validation cycle, including: number of valid Prefixes and Router Keys, current RTR serial number (only when [`--mode=server`](usage.html#--mode)), and real execution time. - Programming errors (of course, those that could be expected due to an API misuse). ### Validation diff --git a/src/reqs_errors.c b/src/reqs_errors.c index 73df8194..31c528d4 100644 --- a/src/reqs_errors.c +++ b/src/reqs_errors.c @@ -115,13 +115,15 @@ reqs_errors_cleanup(void) } static struct error_uri * -find_error_uri(char const *search) +find_error_uri(char const *search, bool lock) { struct error_uri *found; - rwlock_read_lock(&db_lock); + if (lock) + rwlock_read_lock(&db_lock); HASH_FIND_STR(err_uris_db, search, found); - rwlock_unlock(&db_lock); + if (lock) + rwlock_unlock(&db_lock); return found; } @@ -136,7 +138,7 @@ set_working_repo(struct error_uri *err_uri) if (work_uri == NULL) return; - ref = find_error_uri(work_uri); + ref = find_error_uri(work_uri, true); if (ref == NULL) return; @@ -151,7 +153,7 @@ reqs_errors_add_uri(char const *uri) int error; /* Don't overwrite if it already exists */ - found_uri = find_error_uri(uri); + found_uri = find_error_uri(uri, true); if (found_uri != NULL) return 0; @@ -182,16 +184,23 @@ void reqs_errors_rem_uri(char const *uri) { struct error_uri *found_uri; + struct error_uri *tmp; char *ref_uri; - found_uri = find_error_uri(uri); - if (found_uri == NULL) + rwlock_write_lock(&db_lock); + found_uri = find_error_uri(uri, false); + if (found_uri == NULL) { + rwlock_unlock(&db_lock); return; + } - while (found_uri->uri_related != NULL) - found_uri = find_error_uri(found_uri->uri_related); + while (found_uri->uri_related != NULL) { + tmp = find_error_uri(found_uri->uri_related, false); + if (tmp == NULL) + break; + found_uri = tmp; + } - rwlock_write_lock(&db_lock); do { ref_uri = found_uri->ref_by; HASH_DELETE(hh, err_uris_db, found_uri); @@ -199,6 +208,8 @@ reqs_errors_rem_uri(char const *uri) if (ref_uri == NULL) break; HASH_FIND_STR(err_uris_db, ref_uri, found_uri); + if (found_uri == NULL) + break; } while (true); rwlock_unlock(&db_lock); } @@ -241,7 +252,7 @@ reqs_errors_log_uri(char const *uri) if (config_period == 0) return true; - node = find_error_uri(uri); + node = find_error_uri(uri, true); if (node == NULL) return false; diff --git a/src/rrdp/db/db_rrdp.c b/src/rrdp/db/db_rrdp.c index b6e0363b..7487cabf 100644 --- a/src/rrdp/db/db_rrdp.c +++ b/src/rrdp/db/db_rrdp.c @@ -166,7 +166,7 @@ db_rrdp_reset_visited_tals(void) { struct tal_elem *found; - rwlock_read_lock(&lock); + rwlock_write_lock(&lock); SLIST_FOREACH(found, &db.tals, next) found->visited = false; diff --git a/src/rsync/rsync.c b/src/rsync/rsync.c index 6c7f9c55..786e3b32 100644 --- a/src/rsync/rsync.c +++ b/src/rsync/rsync.c @@ -522,7 +522,7 @@ ancestor_error(char const *error_uri, void *arg) error = is_descendant(req_err_uri, search) ? EEXIST : 0; - free(req_err_uri); + uri_refput(req_err_uri); return error; }