summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2020-04-27 15:01:03 +0200
committerGitHub <noreply@github.com>2020-04-27 15:01:03 +0200
commitcc9eceb00d9025d454663857cc03379427023ad8 (patch)
tree252bba3ef5f98dd25304384a4990e8c4c02564d5
parentAdd documentation to the sample config about the templates for SSO. (#7343) (diff)
downloadsynapse-cc9eceb00d9025d454663857cc03379427023ad8.tar.xz
Don't crash when one of the configuration files is empty (#7341)
If the admin adds a `.yaml` file that's either empty or doesn't parse into a dict to a config directory (e.g. `conf.d` for debs installs), stuff like https://github.com/matrix-org/synapse/issues/7322 would happen. This PR checks that the file is correctly parsed into a dict, or ignores it with a warning if it parses into any other type (including `None` for empty files).

Fixes https://github.com/matrix-org/synapse/issues/7322
Diffstat (limited to '')
-rw-r--r--changelog.d/7341.bugfix1
-rw-r--r--synapse/config/_base.py6
2 files changed, 7 insertions, 0 deletions
diff --git a/changelog.d/7341.bugfix b/changelog.d/7341.bugfix
new file mode 100644
index 0000000000..8f0958bcb4
--- /dev/null
+++ b/changelog.d/7341.bugfix
@@ -0,0 +1 @@
+Fix bad error handling that would cause Synapse to crash if it's provided with a YAML configuration file that's either empty or doesn't parse into a key-value map.
diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index bfa9d28999..30d1050a91 100644
--- a/synapse/config/_base.py
+++ b/synapse/config/_base.py
@@ -657,6 +657,12 @@ def read_config_files(config_files):
     for config_file in config_files:
         with open(config_file) as file_stream:
             yaml_config = yaml.safe_load(file_stream)
+
+        if not isinstance(yaml_config, dict):
+            err = "File %r is empty or doesn't parse into a key-value map. IGNORING."
+            print(err % (config_file,))
+            continue
+
         specified_config.update(yaml_config)
 
     if "server_name" not in specified_config: