From 1fb1d952b2514dfc8d55ed84b769403c7740479e Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Sat, 26 Mar 2022 18:44:29 +0100 Subject: [PATCH 2/2] Sanity check: Only allow 'singlepole' requirements when also checking 'alltemperate' See osdn #44181 Signed-off-by: Alina Lenk --- server/rssanity.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/server/rssanity.c b/server/rssanity.c index bb021eecf1..4a5a4cf8b1 100644 --- a/server/rssanity.c +++ b/server/rssanity.c @@ -423,6 +423,57 @@ static bool sanity_check_req_set(int reqs_of_type[], return TRUE; } +/**********************************************************************//** + Helper function: Sanity check potential 'singlepole' server setting + requirement in a requirement vector. + 'conjunctive' should be TRUE if the vector is an AND vector (all + requirements must be active), FALSE if it's a disjunctive (OR) vector. + + Returns TRUE iff everything ok. +**************************************************************************/ +static bool +sanity_check_req_vec_singlepole(const struct requirement_vector *preqs, + bool conjunctive, const char *list_for) +{ + bool has_singlepole_req = FALSE; + + requirement_vector_iterate(preqs, preq) { + server_setting_id id; + struct setting *pset; + + if (preq->source.kind != VUT_SERVERSETTING) { + continue; + } + + id = ssetv_setting_get(preq->source.value.ssetval); + fc_assert_ret_val(server_setting_exists(id), FALSE); + pset = setting_by_number(id); + + if (pset == setting_by_name("singlepole")) { + has_singlepole_req = TRUE; + } else if (pset == setting_by_name("alltemperate") + && XOR(conjunctive, preq->present)) { + return TRUE; + } + } requirement_vector_iterate_end; + + if (!has_singlepole_req) { + /* all good */ + return TRUE; + } + + if (conjunctive) { + log_error("%s: Requirement list containing 'singlepole' server" + " setting requirement must also have negated (!present)" + " 'alltemperate' requirement", list_for); + } else { + log_error("%s: Disjunctive requirement list containing 'singlepole'" + " server setting requirement must also have present" + " 'alltemperate' requirement", list_for); + } + return FALSE; +} + /**********************************************************************//** Sanity check requirement vector, including whether it's free of conflicting requirements. @@ -460,6 +511,10 @@ static bool sanity_check_req_vec(const struct requirement_vector *preqs, } } requirement_vector_iterate_end; + if (!sanity_check_req_vec_singlepole(preqs, conjunctive, list_for)) { + return FALSE; + } + problem = req_vec_suggest_repair(preqs, req_vec_vector_number, preqs); if (problem != NULL) { log_error("%s: %s.", list_for, problem->description); -- 2.17.1