@cryptotaxi247 / netdata-1 / commits / a5eb656f9

fix ExecutableService compatibility + better whitelist checking

paulfantom committed Jul 8, 2016 at 11:07 UTC a5eb656f93d83f0ef1cbbc0941318707247a7175
1 file changed +12 -7
python.d/python_modules/base.py
+12 -7
@@ -565,6 +565,7 @@ class LogService(SimpleService):
565
566 class ExecutableService(SimpleService):
567 command_whitelist = ['exim', 'postqueue']
568 + bad_substrings = ('&', '|', ';', '>', '<')
569
570 def __init__(self, configuration=None, name=None):
571 self.command = ""
@@ -582,7 +583,7 @@ class ExecutableService(SimpleService):
583 return None
584 data = []
585 for line in p.stdout.readlines():
585 - data.append(line)
586 + data.append(str(line.decode()))
587
588 return data
589
@@ -600,19 +601,23 @@ class ExecutableService(SimpleService):
601 # except (KeyError, TypeError):
602 # self.error("No command specified. Using: '" + self.command + "'")
603 self.command = self.command.split(' ')
603 - for i in self.command:
604 - if i.startswith('-') or i in self.command_whitelist:
605 - pass
606 - else:
607 - self.error("Wrong command. Probably not on whitelist.")
604 + if self.command[0] not in self.command_whitelist:
605 + self.error("Command is not whitelisted.")
606 + return False
607 +
608 + for arg in self.command[1:]:
609 + if any(st in arg for st in self.bad_substrings):
610 + self.error("Bad command argument:" + " ".join(self.command[1:]))
611 return False
612 # test command and search for it in /usr/sbin or /sbin when failed
613 base = self.command[0]
614 if self._get_raw_data() is None:
615 for prefix in ['/sbin/', '/usr/sbin/']:
616 self.command[0] = prefix + base
614 - if self._get_raw_data() is not None:
617 + if os.path.isfile(self.command[0]):
618 break
619 + #if self._get_raw_data() is not None:
620 + # break
621
622 if self._get_data() is None or len(self._get_data()) == 0:
623 return False