Skip to content

Commit d24911e

Browse files
babolivierphil-flex
authored andcommitted
Don't crash when one of the configuration files is empty (matrix-org#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 matrix-org#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 matrix-org#7322
1 parent 13fc9cf commit d24911e

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

changelog.d/7341.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

synapse/config/_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,12 @@ def read_config_files(config_files):
657657
for config_file in config_files:
658658
with open(config_file) as file_stream:
659659
yaml_config = yaml.safe_load(file_stream)
660+
661+
if not isinstance(yaml_config, dict):
662+
err = "File %r is empty or doesn't parse into a key-value map. IGNORING."
663+
print(err % (config_file,))
664+
continue
665+
660666
specified_config.update(yaml_config)
661667

662668
if "server_name" not in specified_config:

0 commit comments

Comments
 (0)