Skip to content

Commit 8d6609f

Browse files
committed
Ignore $HOME/.digrc
Newer dig versions have an option to ignore $HOME/.digrc, older don't. This commit adds a patch checking for the availability of such an option and uses it by default. If doesn't exist then still dig is used and can still lead to wrong output. Unfortunately Debian-based distros are not very good at this. Debian 10, Ubuntu 18.04 still use dig 9.11, whereas Opensuse 15.2 has 9.16. Debian 11 and Ubuntu 20.04 use that too. Thus to be considered for the stable 3.0-branch: move dig in the resolver functions a couple of lines down.
1 parent 5d49458 commit 8d6609f

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

testssl.sh

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ HAS_AES128_GCM=false
360360
HAS_AES256_GCM=false
361361
HAS_ZLIB=false
362362
HAS_DIG=false
363+
HAS_DIG_R=true
364+
DIG_R='-r'
363365
HAS_HOST=false
364366
HAS_DRILL=false
365367
HAS_NSLOOKUP=false
@@ -17409,6 +17411,7 @@ HAS_IDN: $HAS_IDN
1740917411
HAS_IDN2: $HAS_IDN2
1741017412
HAS_AVAHIRESOLVE: $HAS_AVAHIRESOLVE
1741117413
HAS_DIG_NOIDNOUT: $HAS_DIG_NOIDNOUT
17414+
HAS_DIG_R: $HAS_DIG_R
1741217415

1741317416
PATH: $PATH
1741417417
PROG_NAME: $PROG_NAME
@@ -17857,12 +17860,18 @@ check_resolver_bins() {
1785717860
type -p idn &>/dev/null && HAS_IDN=true
1785817861
type -p idn2 &>/dev/null && HAS_IDN2=true
1785917862

17863+
# Old dig versions don't have an option to ignore $HOME/.digrc
17864+
if dig -r 2>&1 | grep -qiE 'invalid|usage'; then
17865+
HAS_DIG_R=false
17866+
DIG_R=""
17867+
fi
17868+
1786017869
OPENSSL_CONF="" # see https://github.com/drwetter/testssl.sh/issues/134
1786117870
if ! "$HAS_DIG" && ! "$HAS_HOST" && ! "$HAS_DRILL" && ! "$HAS_NSLOOKUP"; then
1786217871
fatal "Neither \"dig\", \"host\", \"drill\" or \"nslookup\" is present" $ERR_DNSBIN
1786317872
fi
1786417873
if "$HAS_DIG"; then
17865-
if dig +noidnout -t a 2>&1 | grep -Eq 'Invalid option: \+noidnout|IDN support not enabled'; then
17874+
if dig $DIG_R +noidnout -t a 2>&1 | grep -Eq 'Invalid option: \+noidnout|IDN support not enabled'; then
1786617875
:
1786717876
else
1786817877
HAS_DIG_NOIDNOUT=true
@@ -17896,13 +17905,13 @@ get_a_record() {
1789617905
if "$HAS_AVAHIRESOLVE"; then
1789717906
ip4=$(filter_ip4_address $(avahi-resolve -4 -n "$1" 2>/dev/null | awk '{ print $2 }'))
1789817907
elif "$HAS_DIG"; then
17899-
ip4=$(filter_ip4_address $(dig @224.0.0.251 -p 5353 +short -t a +notcp "$1" 2>/dev/null | sed '/^;;/d'))
17908+
ip4=$(filter_ip4_address $(dig $DIG_R @224.0.0.251 -p 5353 +short -t a +notcp "$1" 2>/dev/null | sed '/^;;/d'))
1790017909
else
1790117910
fatal "Local hostname given but no 'avahi-resolve' or 'dig' available." $ERR_DNSBIN
1790217911
fi
1790317912
fi
1790417913
if [[ -z "$ip4" ]] && "$HAS_DIG"; then
17905-
ip4=$(filter_ip4_address $(dig +short +timeout=2 +tries=2 $noidnout -t a "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
17914+
ip4=$(filter_ip4_address $(dig $DIG_R +short +timeout=2 +tries=2 $noidnout -t a "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
1790617915
fi
1790717916
if [[ -z "$ip4" ]] && "$HAS_HOST"; then
1790817917
ip4=$(filter_ip4_address $(host -t a "$1" 2>/dev/null | awk '/address/ { print $NF }'))
@@ -17940,12 +17949,12 @@ get_aaaa_record() {
1794017949
if "$HAS_AVAHIRESOLVE"; then
1794117950
ip6=$(filter_ip6_address $(avahi-resolve -6 -n "$1" 2>/dev/null | awk '{ print $2 }'))
1794217951
elif "$HAS_DIG"; then
17943-
ip6=$(filter_ip6_address $(dig @ff02::fb -p 5353 -t aaaa +short +notcp "$NODE"))
17952+
ip6=$(filter_ip6_address $(dig $DIG_R @ff02::fb -p 5353 -t aaaa +short +notcp "$NODE"))
1794417953
else
1794517954
fatal "Local hostname given but no 'avahi-resolve' or 'dig' available." $ERR_DNSBIN
1794617955
fi
1794717956
elif "$HAS_DIG"; then
17948-
ip6=$(filter_ip6_address $(dig +short +timeout=2 +tries=2 $noidnout -t aaaa "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
17957+
ip6=$(filter_ip6_address $(dig $DIG_R +short +timeout=2 +tries=2 $noidnout -t aaaa "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
1794917958
elif "$HAS_HOST"; then
1795017959
ip6=$(filter_ip6_address $(host -t aaaa "$1" | awk '/address/ { print $NF }'))
1795117960
elif "$HAS_DRILL"; then
@@ -17980,7 +17989,7 @@ get_caa_rr_record() {
1798017989
# caa_property then has key/value pairs, see https://tools.ietf.org/html/rfc6844#section-3
1798117990
OPENSSL_CONF=""
1798217991
if "$HAS_DIG"; then
17983-
raw_caa="$(dig +short +timeout=3 +tries=3 $noidnout type257 "$1" 2>/dev/null | awk '{ print $1" "$2" "$3 }')"
17992+
raw_caa="$(dig $DIG_R +short +timeout=3 +tries=3 $noidnout type257 "$1" 2>/dev/null | awk '{ print $1" "$2" "$3 }')"
1798417993
# empty if no CAA record
1798517994
elif "$HAS_DRILL"; then
1798617995
raw_caa="$(drill $1 type257 | awk '/'"^${1}"'.*CAA/ { print $5,$6,$7 }')"
@@ -18051,7 +18060,7 @@ get_mx_record() {
1805118060
if "$HAS_HOST"; then
1805218061
mxs="$(host -t MX "$1" 2>/dev/null | awk '/is handled by/ { print $(NF-1), $NF }')"
1805318062
elif "$HAS_DIG"; then
18054-
mxs="$(dig +short $noidnout -t MX "$1" 2>/dev/null | awk '/^[0-9]/ { print $1" "$2 }')"
18063+
mxs="$(dig $DIG_R +short $noidnout -t MX "$1" 2>/dev/null | awk '/^[0-9]/ { print $1" "$2 }')"
1805518064
elif "$HAS_DRILL"; then
1805618065
mxs="$(drill mx $1 | awk '/IN[ \t]MX[ \t]+/ { print $(NF-1), $NF }')"
1805718066
elif "$HAS_NSLOOKUP"; then
@@ -18150,11 +18159,11 @@ determine_rdns() {
1815018159
if "$HAS_AVAHIRESOLVE"; then
1815118160
rDNS=$(avahi-resolve -a $nodeip 2>/dev/null | awk '{ print $2 }')
1815218161
elif "$HAS_DIG"; then
18153-
rDNS=$(dig -x $nodeip @224.0.0.251 -p 5353 +notcp +noall +answer +short | awk '{ print $1 }')
18162+
rDNS=$(dig $DIG_R -x $nodeip @224.0.0.251 -p 5353 +notcp +noall +answer +short | awk '{ print $1 }')
1815418163
fi
1815518164
elif "$HAS_DIG"; then
1815618165
# 1+2 should suffice. It's a compromise for if e.g. network is down but we have a docker/localhost server
18157-
rDNS=$(dig -x $nodeip +timeout=1 +tries=2 +noall +answer +short | awk '{ print $1 }') # +short returns also CNAME, e.g. openssl.org
18166+
rDNS=$(dig $DIG_R -x $nodeip +timeout=1 +tries=2 +noall +answer +short | awk '{ print $1 }') # +short returns also CNAME, e.g. openssl.org
1815818167
elif "$HAS_HOST"; then
1815918168
rDNS=$(host -t PTR $nodeip 2>/dev/null | awk '/pointer/ { print $NF }')
1816018169
elif "$HAS_DRILL"; then

0 commit comments

Comments
 (0)