From ec18847f3eddd5f3e42bc121d06ecfb961db620c Mon Sep 17 00:00:00 2001 From: William Erik Baxter Date: Sun, 4 Dec 2022 05:47:15 -0600 Subject: [PATCH] Fix bug in ip-in-use test Need grep -wF instead of grep -w for IP test to avoid spurious match against broadcast address in ifconfig output. --- usr/local/share/bastille/clone.sh | 2 +- usr/local/share/bastille/create.sh | 2 +- usr/local/share/bastille/start.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/usr/local/share/bastille/clone.sh b/usr/local/share/bastille/clone.sh index edc9a7fa..5630b71d 100644 --- a/usr/local/share/bastille/clone.sh +++ b/usr/local/share/bastille/clone.sh @@ -68,7 +68,7 @@ validate_ip() { error_exit "Invalid: (${TEST_IP})" fi done - if ifconfig | grep -qw "${TEST_IP}"; then + if ifconfig | grep -qwF "${TEST_IP}"; then warn "Warning: IP address already in use (${TEST_IP})." else info "Valid: (${IP})." diff --git a/usr/local/share/bastille/create.sh b/usr/local/share/bastille/create.sh index c4533fe6..bc2cf700 100644 --- a/usr/local/share/bastille/create.sh +++ b/usr/local/share/bastille/create.sh @@ -91,7 +91,7 @@ validate_ip() { exit 1 fi done - if ifconfig | grep -qw "${TEST_IP}"; then + if ifconfig | grep -qwF "${TEST_IP}"; then warn "Warning: IP address already in use (${TEST_IP})." else info "Valid: (${ip})." diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index a82fb611..8cac4c50 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -79,7 +79,7 @@ for _jail in ${JAILS}; do ## warn if matching configured (but not online) ip4.addr, ignore if there's no ip4.addr entry ip=$(grep 'ip4.addr' "${bastille_jailsdir}/${_jail}/jail.conf" | awk '{print $3}' | sed 's/\;//g') if [ -n "${ip}" ]; then - if ifconfig | grep -w "${ip}" >/dev/null; then + if ifconfig | grep -wF "${ip}" >/dev/null; then error_notify "Error: IP address (${ip}) already in use." continue fi