@@ -189,6 +189,8 @@ def _switch_profile(self, profile_name, manual):
189189 def switch_profile (self , profile_name , caller = None ):
190190 if caller == "" :
191191 return (False , "Unauthorized" )
192+ if not self ._cmd .is_valid_name (profile_name ):
193+ return (False , "Invalid profile_name" )
192194 return self ._switch_profile (profile_name , True )
193195
194196 @exports .export ("" , "(bs)" )
@@ -262,8 +264,8 @@ def profiles2(self, caller = None):
262264
263265 @exports .export ("s" , "(bsss)" )
264266 def profile_info (self , profile_name , caller = None ):
265- if caller == "" :
266- return tuple (False , "" , "" , "" )
267+ if caller == "" or not self . _cmd . is_valid_name ( profile_name ) :
268+ return (False , "" , "" , "" )
267269 if profile_name is None or profile_name == "" :
268270 profile_name = self .active_profile ()
269271 return tuple (self ._daemon .profile_loader .profile_locator .get_profile_attrs (profile_name , [consts .PROFILE_ATTR_SUMMARY , consts .PROFILE_ATTR_DESCRIPTION ], ["" ]))
@@ -294,7 +296,7 @@ def get_all_plugins(self, caller = None):
294296 dictionary -- {plugin_name: {parameter_name: default_value}}
295297 """
296298 if caller == "" :
297- return False
299+ return {}
298300 plugins = {}
299301 for plugin_class in self ._daemon .get_all_plugins ():
300302 plugin_name = plugin_class .__module__ .split ("." )[- 1 ].split ("_" , 1 )[1 ]
@@ -307,8 +309,8 @@ def get_all_plugins(self, caller = None):
307309 @exports .export ("s" ,"s" )
308310 def get_plugin_documentation (self , plugin_name , caller = None ):
309311 """Return docstring of plugin's class"""
310- if caller == "" :
311- return False
312+ if caller == "" or not self . _cmd . is_valid_name ( plugin_name ) :
313+ return ""
312314 return self ._daemon .get_plugin_documentation (str (plugin_name ))
313315
314316 @exports .export ("s" ,"a{ss}" )
@@ -321,8 +323,8 @@ def get_plugin_hints(self, plugin_name, caller = None):
321323 Return:
322324 dictionary -- {parameter_name: hint}
323325 """
324- if caller == "" :
325- return False
326+ if caller == "" or not self . _cmd . is_valid_name ( plugin_name ) :
327+ return {}
326328 return self ._daemon .get_plugin_hints (str (plugin_name ))
327329
328330 @exports .export ("s" , "b" )
@@ -335,7 +337,7 @@ def register_socket_signal_path(self, path, caller = None):
335337 Return:
336338 bool -- True on success
337339 """
338- if caller == "" :
340+ if caller == "" or not self . _cmd . is_valid_name ( path ) :
339341 return False
340342 if self ._daemon ._application and self ._daemon ._application ._unix_socket_exporter :
341343 self ._daemon ._application ._unix_socket_exporter .register_signal_path (path )
@@ -349,6 +351,10 @@ def register_socket_signal_path(self, path, caller = None):
349351 def instance_acquire_devices (self , devices , instance_name , caller = None ):
350352 if caller == "" :
351353 return (False , "Unauthorized" )
354+ if not self ._cmd .is_valid_name (devices ):
355+ return (False , "Invalid devices" )
356+ if not self ._cmd .is_valid_name (instance_name ):
357+ return (False , "Invalid instance_name" )
352358 found = False
353359 for instance_target in self ._daemon ._unit_manager .instances :
354360 if instance_target .name == instance_name :
@@ -399,6 +405,8 @@ def get_instances(self, plugin_name, caller = None):
399405 """
400406 if caller == "" :
401407 return (False , "Unauthorized" , [])
408+ if not self ._cmd .is_valid_name (plugin_name ):
409+ return (False , "Invalid plugin_name" , [])
402410 if plugin_name != "" and plugin_name not in self .get_all_plugins ().keys ():
403411 rets = "Plugin '%s' does not exist" % plugin_name
404412 log .error (rets )
@@ -422,6 +430,8 @@ def instance_get_devices(self, instance_name, caller = None):
422430 """
423431 if caller == "" :
424432 return (False , "Unauthorized" , [])
433+ if not self ._cmd .is_valid_name (instance_name ):
434+ return (False , "Invalid instance_name" , [])
425435 for instance in self ._daemon ._unit_manager .instances :
426436 if instance .name == instance_name :
427437 return (True , "OK" , sorted (list (instance .processed_devices )))
@@ -444,6 +454,13 @@ def instance_create(self, plugin_name, instance_name, options, caller = None):
444454 """
445455 if caller == "" :
446456 return (False , "Unauthorized" )
457+ if not self ._cmd .is_valid_name (plugin_name ):
458+ return (False , "Invalid plugin_name" )
459+ if not self ._cmd .is_valid_name (instance_name ):
460+ return (False , "Invalid instance_name" )
461+ for (key , value ) in options .items ():
462+ if not self ._cmd .is_valid_name (key ) or not self ._cmd .is_valid_name (value ):
463+ return (False , "Invalid options" )
447464 plugins = {p .name : p for p in self ._daemon ._unit_manager .plugins }
448465 if not plugin_name in plugins .keys ():
449466 rets = "Plugin '%s' not found" % plugin_name
@@ -499,6 +516,8 @@ def instance_destroy(self, instance_name, caller = None):
499516 """
500517 if caller == "" :
501518 return (False , "Unauthorized" )
519+ if not self ._cmd .is_valid_name (instance_name ):
520+ return (False , "Invalid instance_name" )
502521 try :
503522 instance = [i for i in self ._daemon ._unit_manager .instances if i .name == instance_name ][0 ]
504523 except IndexError :
0 commit comments