Skip to content

Commit

Permalink
Merge pull request #1151 from whisperity/bailout-if-sessioncfg-bogus
Browse files Browse the repository at this point in the history
Don't start server if session_config.json is syntactically incorrect
  • Loading branch information
dkrupp authored Nov 24, 2017
2 parents a41564c + f572483 commit 54492bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 8 additions & 3 deletions libcodechecker/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import stat
import socket
import ssl
import sys
import urllib

try:
Expand Down Expand Up @@ -761,6 +762,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,
Expand All @@ -770,9 +777,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(),
Expand Down
8 changes: 7 additions & 1 deletion libcodechecker/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"] = {}
Expand Down

0 comments on commit 54492bc

Please sign in to comment.