Merge pull request #4869 from matrix-org/erikj/yaml_load

Fix yaml warnings by using safe_load
pull/4923/head
Erik Johnston 2019-03-22 11:58:13 +00:00 committed by GitHub
commit 5fee9d8067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 11 deletions

1
changelog.d/4869.misc Normal file
View File

@ -0,0 +1 @@
Fix yaml library warnings by using safe_load.

View File

@ -76,7 +76,7 @@ def rows_v2(server, json):
def main(): def main():
config = yaml.load(open(sys.argv[1])) config = yaml.safe_load(open(sys.argv[1]))
valid_until = int(time.time() / (3600 * 24)) * 1000 * 3600 * 24 valid_until = int(time.time() / (3600 * 24)) * 1000 * 3600 * 24
server_name = config["server_name"] server_name = config["server_name"]

View File

@ -137,7 +137,7 @@ class Config(object):
@staticmethod @staticmethod
def read_config_file(file_path): def read_config_file(file_path):
with open(file_path) as file_stream: with open(file_path) as file_stream:
return yaml.load(file_stream) return yaml.safe_load(file_stream)
def invoke_all(self, name, *args, **kargs): def invoke_all(self, name, *args, **kargs):
results = [] results = []
@ -318,7 +318,7 @@ class Config(object):
) )
config_file.write(config_str) config_file.write(config_str)
config = yaml.load(config_str) config = yaml.safe_load(config_str)
obj.invoke_all("generate_files", config) obj.invoke_all("generate_files", config)
print( print(
@ -390,7 +390,7 @@ class Config(object):
server_name=server_name, server_name=server_name,
generate_secrets=False, generate_secrets=False,
) )
config = yaml.load(config_string) config = yaml.safe_load(config_string)
config.pop("log_config") config.pop("log_config")
config.update(specified_config) config.update(specified_config)

View File

@ -68,7 +68,7 @@ def load_appservices(hostname, config_files):
try: try:
with open(config_file, 'r') as f: with open(config_file, 'r') as f:
appservice = _load_appservice( appservice = _load_appservice(
hostname, yaml.load(f), config_file hostname, yaml.safe_load(f), config_file
) )
if appservice.id in seen_ids: if appservice.id in seen_ids:
raise ConfigError( raise ConfigError(

View File

@ -195,7 +195,7 @@ def setup_logging(config, use_worker_options=False):
else: else:
def load_log_config(): def load_log_config():
with open(log_config, 'r') as f: with open(log_config, 'r') as f:
logging.config.dictConfig(yaml.load(f)) logging.config.dictConfig(yaml.safe_load(f))
def sighup(*args): def sighup(*args):
# it might be better to use a file watcher or something for this. # it might be better to use a file watcher or something for this.

4
synctl
View File

@ -164,7 +164,7 @@ def main():
sys.exit(1) sys.exit(1)
with open(configfile) as stream: with open(configfile) as stream:
config = yaml.load(stream) config = yaml.safe_load(stream)
pidfile = config["pid_file"] pidfile = config["pid_file"]
cache_factor = config.get("synctl_cache_factor") cache_factor = config.get("synctl_cache_factor")
@ -206,7 +206,7 @@ def main():
workers = [] workers = []
for worker_configfile in worker_configfiles: for worker_configfile in worker_configfiles:
with open(worker_configfile) as stream: with open(worker_configfile) as stream:
worker_config = yaml.load(stream) worker_config = yaml.safe_load(stream)
worker_app = worker_config["worker_app"] worker_app = worker_config["worker_app"]
if worker_app == "synapse.app.homeserver": if worker_app == "synapse.app.homeserver":
# We need to special case all of this to pick up options that may # We need to special case all of this to pick up options that may

View File

@ -43,7 +43,7 @@ class ConfigLoadingTestCase(unittest.TestCase):
self.generate_config() self.generate_config()
with open(self.file, "r") as f: with open(self.file, "r") as f:
raw = yaml.load(f) raw = yaml.safe_load(f)
self.assertIn("macaroon_secret_key", raw) self.assertIn("macaroon_secret_key", raw)
config = HomeServerConfig.load_config("", ["-c", self.file]) config = HomeServerConfig.load_config("", ["-c", self.file])

View File

@ -22,7 +22,7 @@ from tests import unittest
class RoomDirectoryConfigTestCase(unittest.TestCase): class RoomDirectoryConfigTestCase(unittest.TestCase):
def test_alias_creation_acl(self): def test_alias_creation_acl(self):
config = yaml.load(""" config = yaml.safe_load("""
alias_creation_rules: alias_creation_rules:
- user_id: "*bob*" - user_id: "*bob*"
alias: "*" alias: "*"
@ -74,7 +74,7 @@ class RoomDirectoryConfigTestCase(unittest.TestCase):
)) ))
def test_room_publish_acl(self): def test_room_publish_acl(self):
config = yaml.load(""" config = yaml.safe_load("""
alias_creation_rules: [] alias_creation_rules: []
room_list_publication_rules: room_list_publication_rules: