From f572483a3e9f1afda1108f99d8b363065fbd9c7e Mon Sep 17 00:00:00 2001 From: Whisperity Date: Sat, 18 Nov 2017 10:45:44 +0100 Subject: [PATCH] Don't start server if session_config.json is syntactically incorrect --- libcodechecker/server/server.py | 11 ++++++++--- libcodechecker/session_manager.py | 8 +++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libcodechecker/server/server.py b/libcodechecker/server/server.py index 4b024e47cd..16661538ce 100644 --- a/libcodechecker/server/server.py +++ b/libcodechecker/server/server.py @@ -19,6 +19,7 @@ import stat import socket import ssl +import sys import urllib try: @@ -748,6 +749,12 @@ def start_server(config_directory, package_data, port, db_conn_string, .format(root_file)) root_sha = __make_root_file(root_file) + try: + manager = session_manager.SessionManager(root_sha, force_auth) + except IOError, ValueError: + LOG.error("The server's authentication config file is invalid!") + sys.exit(1) + http_server = CCSimpleHttpServer(server_addr, RequestHandler, config_directory, @@ -757,9 +764,7 @@ def start_server(config_directory, package_data, port, db_conn_string, suppress_handler, context, check_env, - session_manager.SessionManager( - root_sha, force_auth) - ) + manager) try: instance_manager.register(os.getpid(), diff --git a/libcodechecker/session_manager.py b/libcodechecker/session_manager.py index 7e074e018b..95580992ad 100644 --- a/libcodechecker/session_manager.py +++ b/libcodechecker/session_manager.py @@ -145,10 +145,12 @@ def load_session_cfg(session_cfg_file): except IOError: LOG.debug('Failed to open user authentication file: ' + session_cfg_file) + raise except ValueError as verr: LOG.warning(verr) LOG.warning('Not valid user authentication file: ' + session_cfg_file) + raise return scfg_dict @@ -442,7 +444,11 @@ def __init__(self): ".codechecker.passwords.json") LOG.debug(session_cfg_file) - scfg_dict = load_session_cfg(session_cfg_file) + try: + scfg_dict = load_session_cfg(session_cfg_file) + except (IOError, ValueError): + # On the client's side, continue execution with defaults. + scfg_dict = {} if not scfg_dict.get("credentials"): scfg_dict["credentials"] = {}