Skip to content

Commit

Permalink
Fix frontend uniqueness check, where IP=* is a NULL pointer
Browse files Browse the repository at this point in the history
Fixes #317
  • Loading branch information
dmatetelki authored and daghf committed Nov 22, 2019
1 parent 95161db commit 9c13b2b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,16 +745,30 @@ 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;
}
}

if (retval == 0) {
config_error_set("Redundant frontend "
"(matching IP and port) definition: '%s:%s'.",
fa->ip, fa->port);
}
return(1);

return(retval);
}

int
Expand Down
84 changes: 84 additions & 0 deletions src/tests/test34-unique-fa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/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_good_cfg() {
test_cfg "$1" -s 0
}

test_bad_cfg bad1 <<EOF
frontend = {
host = "*"
port = "443"
}
frontend = {
host = "*"
port = "443"
}
EOF

test_good_cfg good1 <<EOF
frontend = {
host = "*"
port = "443"
}
frontend = {
host = "*"
port = "444"
}
EOF

test_good_cfg good2 <<EOF
frontend = {
host = "*"
port = "443"
}
frontend = {
host = "fd22:5979:45f3:9471::1"
port = "443"
}
EOF

test_bad_cfg bad2 <<EOF
frontend = {
host = "fd22:5979:45f3:9471::1"
port = "443"
}
frontend = {
host = "fd22:5979:45f3:9471::1"
port = "443"
}
EOF

test_good_cfg good3 <<EOF
frontend = {
host = "fd22:5979:45f3:9471::1"
port = "443"
}
frontend = {
host = "fd22:5979:45f3:9471::1"
port = "444"
}
EOF

0 comments on commit 9c13b2b

Please sign in to comment.