From 3c1ce6aadc3c014787023e5d9d82d16967d2229e Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Wed, 13 Nov 2019 15:17:41 +0100 Subject: [PATCH] Fix frontend uniqueness check, where IP=* is a NULL pointer Fixes #317 --- src/configuration.c | 28 +++++++++++--- src/tests/test34-unique-fa.sh | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) create mode 100755 src/tests/test34-unique-fa.sh diff --git a/src/configuration.c b/src/configuration.c index a3e54ec8..ee18eca1 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -745,16 +745,32 @@ static int check_frontend_uniqueness(struct front_arg *cur_fa, hitch_config *cfg) { struct front_arg *fa, *fatmp; + int retval = 1; + HASH_ITER(hh, cfg->LISTEN_ARGS, fa, fatmp) { - if ((cur_fa->ip == NULL || strcmp(cur_fa->ip, fa->ip) == 0) && + if (cur_fa->ip == NULL && fa->ip == NULL && strcmp(cur_fa->port, fa->port) == 0) { - config_error_set("Redundant frontend " - "(matching IP and port) definition: '%s:%s'.", - fa->ip, fa->port); - return (0); + retval = 0; + break; + } + else if (cur_fa->ip == NULL || fa->ip == NULL) + continue; + else { + if (strcmp(cur_fa->ip, fa->ip) == 0 && + strcmp(cur_fa->port, fa->port) == 0) { + retval = 0; + break; + } } } - return(1); + + if (retval == 0) { + config_error_set("Redundant frontend " + "(matching IP and port) definition: '%s:%s'.", + fa->ip, fa->port); + } + + return(retval); } int diff --git a/src/tests/test34-unique-fa.sh b/src/tests/test34-unique-fa.sh new file mode 100755 index 00000000..479d7149 --- /dev/null +++ b/src/tests/test34-unique-fa.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Test check_frontend_uniqueness +. hitch_test.sh + +GRP=$(id -gn nobody) || +skip 'no usable group found for user nobody' + +test_cfg() { + cfg=$1.cfg + shift + cat >"$cfg" + run_cmd "$@" hitch \ + --test \ + --config="$cfg" \ + "${CERTSDIR}/default.example.com" +} + +test_bad_cfg() { + test_cfg "$1" -s 1 +} + + +test_bad_cfg bad1 <