Skip to content

Commit 9fcf434

Browse files
committed
Firewall ipset: filter out entries with invalid ip4/6 format
Fixes hestiacp#939
1 parent 794d9f0 commit 9fcf434

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

bin/v-add-firewall-ipset

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ if [ ! -f "${IPSET_PATH}/${IPSET_FILE}.iplist" ] || [ "$force" = "yes" ]; then
115115

116116
fi
117117

118+
# Cleanup ip list
119+
if [[ $ip_version == 'v4' ]]; then
120+
sed -i -r -n -e '/^((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/p' "$iplist_tempfile"
121+
elif [[ $ip_version == 'v6' ]]; then
122+
sed -i -r -n -e '/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}/p' "$iplist_tempfile"
123+
fi
124+
118125
# Validate iplist file size
119126
iplist_size=$(sed -r -e '/^#|^$/d' "$iplist_tempfile" | wc -l)
120127
[[ "$iplist_size" -le $IPSET_MIN_SIZE ]] && check_result $E_INVALID "iplist file too small (<${IPSET_MIN_SIZE}), ignoring"

0 commit comments

Comments
 (0)