Skip to content

Commit

Permalink
Merge pull request #3186 from pi-hole/fix/awkInQuery
Browse files Browse the repository at this point in the history
Malformed wildcard blocking doesn't crash awk.
  • Loading branch information
dschaper committed Mar 2, 2020
2 parents dc8ae4f + bf4fada commit f617ed2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions advanced/Scripts/query.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ scanList(){
export LC_CTYPE=C

# /dev/null forces filename to be printed when only one list has been generated
# shellcheck disable=SC2086
case "${type}" in
"exact" ) grep -i -E -l "(^|(?<!#)\\s)${esc_domain}($|\\s|#)" ${lists} /dev/null 2>/dev/null;;
# Create array of regexps
# Iterate through each regexp and check whether it matches the domainQuery
# If it does, print the matching regexp and continue looping
# Input 1 - regexps | Input 2 - domainQuery
"regex" ) awk 'NR==FNR{regexps[$0];next}{for (r in regexps)if($0 ~ r)print r}' \
<(echo "${lists}") <(echo "${domain}") 2>/dev/null;;
"regex" )
for list in ${lists}; do
if [[ "${domain}" =~ ${list} ]]; then
printf "%b\n" "${list}";
fi
done;;
* ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;;
esac
}
Expand Down

0 comments on commit f617ed2

Please sign in to comment.