More messagetypes hardening

- only load modules at program start
This commit is contained in:
Peter Šurda 2018-02-19 16:57:47 +01:00
parent 757740369b
commit fde194f9b0
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
1 changed files with 4 additions and 4 deletions

View File

@ -3,6 +3,7 @@ from os import path, listdir
from string import lower
from debug import logger
import messagetypes
import paths
class MsgBase(object):
@ -15,9 +16,8 @@ def constructObject(data):
if data[""] not in whitelist:
return None
try:
m = import_module("messagetypes." + data[""])
classBase = getattr(m, data[""].title())
except (NameError, ImportError):
classBase = getattr(getattr(messagetypes, data[""]), data[""].title())
except (NameError, AttributeError):
logger.error("Don't know how to handle message type: \"%s\"", data[""], exc_info=True)
return None
try:
@ -43,7 +43,7 @@ else:
if splitted[1] != ".py":
continue
try:
import_module("." + splitted[0], "messagetypes")
import_module(".{}".format(splitted[0]), "messagetypes")
except ImportError:
logger.error("Error importing %s", mod, exc_info=True)
else: