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 committed Nov 13, 2019
1 parent 95161db commit 3c1ce6a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions src/tests/test34-unique-fa.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
frontend = {
host = "*"
port = "443"
}
frontend = {
host = "*"
port = "443"
}
EOF

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

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

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

0 comments on commit 3c1ce6a

Please sign in to comment.