Skip to content

Commit

Permalink
Validate given record type (Fix #98)
Browse files Browse the repository at this point in the history
  • Loading branch information
farrokhi committed Mar 9, 2023
1 parent 694b4a2 commit e2e3a68
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dnseval.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def main():
print("Invalid option: %s" % o)
usage()

# validate RR type
if not util.dns.valid_rdatatype(rdatatype):
print('Error: Invalid record type "%s" ' % rdatatype)
sys.exit(1)

color = Colors(color_mode)

try:
Expand All @@ -174,7 +179,7 @@ def main():
f = dns.resolver.get_default_resolver().nameservers

if len(f) == 0:
print("No nameserver specified")
print("Error: No nameserver specified")

f = [name.strip() for name in f] # remove annoying blanks
f = [x for x in f if not x.startswith('#') and len(x)] # remove comments and empty entries
Expand Down
6 changes: 6 additions & 0 deletions dnsping.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import dns.resolver
import requests

import util.dns
from util.dns import PROTO_UDP, PROTO_TCP, PROTO_TLS, PROTO_HTTPS, proto_to_text, unsupported_feature, random_string
from util.shared import __version__

Expand Down Expand Up @@ -209,6 +210,11 @@ def main():
response_time = []
i = 0

# validate RR type
if not util.dns.valid_rdatatype(rdatatype):
print('Error: Invalid record type "%s" ' % rdatatype)
sys.exit(1)

print("%s DNS: %s:%d, hostname: %s, proto: %s, type: %s, flags: [%s]" %
(__progname__, dnsserver, dst_port, qname, proto_to_text(proto), rdatatype,
dns.flags.to_text(request_flags)), flush=True)
Expand Down
5 changes: 5 additions & 0 deletions dnstraceroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ def main():

color = Colors(color_mode)

# validate RR type
if not util.dns.valid_rdatatype(rdatatype):
print('Error: Invalid record type "%s" ' % rdatatype)
sys.exit(1)

# Use system DNS server if parameter is not specified
# remember not all systems have /etc/resolv.conf (i.e. Android)
if dnsserver is None:
Expand Down
9 changes: 9 additions & 0 deletions util/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ def unsupported_feature():
sys.exit(127)


def valid_rdatatype(rtype):
# validate RR type
try:
_ = dns.rdatatype.from_text(rtype)
except dns.rdatatype.UnknownRdatatype:
return False
return True


def flags_to_text(flags):
# Standard DNS flags

Expand Down

0 comments on commit e2e3a68

Please sign in to comment.