From: Philipp Spitzer Date: Wed, 5 Mar 2014 22:05:36 +0000 (+0100) Subject: Moved hostname handling into try block to avoid an unhandled exception in case of... X-Git-Tag: 0.0.2~31 X-Git-Url: https://git.toastfreeware.priv.at/toast/tdyndns.git/commitdiff_plain/bfb6f4377d8cfc29384eec4c0bf2aeb461c69377 Moved hostname handling into try block to avoid an unhandled exception in case of missing hostname. --- diff --git a/cgi-bin/dyndns.py b/cgi-bin/dyndns.py index b89cd39..7863b79 100755 --- a/cgi-bin/dyndns.py +++ b/cgi-bin/dyndns.py @@ -34,11 +34,6 @@ backmx = fields.getvalue('backmx') offline = fields.getvalue('offline') -# Strip zone -hostname = hostname.strip() -if hostname.endswith(ZONE): - hostname = hostname[:-len(ZONE)] - try: # check username user_info = pwd.getpwnam(username) # returns a key error if the user does not exist @@ -53,6 +48,11 @@ try: if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', hostname) is None: raise RuntimeError('Invalid host name') + # strip zone + hostname = hostname.strip() + if hostname.endswith(ZONE): + hostname = hostname[:-len(ZONE)] + # check IP address ip = ipaddr.IPAddress(myip) # throws axception if the IP address is not valid if isinstance(ip, ipaddr.IPv4Address):