From 30b7b0ddbe67b5667c9d05c698e48566b3518f4b Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sat, 4 Jan 2025 06:48:04 +0100 Subject: [PATCH] Factor out newer_privoxy_version_required() and improve the logic Previously 3.0.11 was considered newer than 4.0.0. --- actions.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/actions.c b/actions.c index 9fd3249c..00c38b6e 100644 --- a/actions.c +++ b/actions.c @@ -1210,6 +1210,45 @@ static int action_spec_is_valid(struct client_state *csp, const struct action_sp } +/********************************************************************* + * + * Function : newer_privoxy_version_required + * + * Description : Figures out whether or not an action file requires + * a more recent Privoxy version. + * + * Parameters : + * 1 : required_major = Required major version. + * 2 : required_minor = Required minor version, or NULL. + * 3 : required_point = Required point release, or NULL. + * + * Returns : 1 => Yes, 0 => No. + * + *********************************************************************/ +static int newer_privoxy_version_required(const char *required_major, + const char *required_minor, const char *required_point) +{ + if (atoi(required_major) > VERSION_MAJOR) + { + return 1; + } + if (atoi(required_major) < VERSION_MAJOR) + { + return 0; + } + if ((required_minor == NULL) || (atoi(required_minor) < VERSION_MINOR)) + { + return 0; + } + if ((required_point == NULL) || (atoi(required_point) <= VERSION_POINT)) + { + return 0; + } + + return 1; +} + + /********************************************************************* * * Function : load_one_actions_file @@ -1489,9 +1528,7 @@ int load_one_actions_file(struct client_state *csp, int fileid) "While loading actions file '%s': invalid line (%lu): %s", csp->config->actions_file[fileid], linenum, buf); } - else if ( (atoi(fields[0]) > VERSION_MAJOR) - || ((num_fields > 1) && (atoi(fields[1]) > VERSION_MINOR)) - || ((num_fields > 2) && (atoi(fields[2]) > VERSION_POINT))) + else if (newer_privoxy_version_required(fields[0], fields[1], fields[2])) { fclose(fp); log_error(LOG_LEVEL_FATAL, -- 2.49.0