mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-19 21:07:28 +08:00
fix: exception handling in config eval
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# encoding:utf-8
|
# encoding:utf-8
|
||||||
|
|
||||||
|
import ast
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@@ -427,9 +428,12 @@ def load_config():
|
|||||||
# ast.literal_eval only parses Python literals (strings, numbers,
|
# ast.literal_eval only parses Python literals (strings, numbers,
|
||||||
# tuples, lists, dicts, booleans, None) and CANNOT execute
|
# tuples, lists, dicts, booleans, None) and CANNOT execute
|
||||||
# arbitrary code, preventing environment-variable injection.
|
# arbitrary code, preventing environment-variable injection.
|
||||||
import ast
|
|
||||||
config[name] = ast.literal_eval(value)
|
config[name] = ast.literal_eval(value)
|
||||||
except (ValueError, SyntaxError):
|
except Exception:
|
||||||
|
# literal_eval can raise ValueError/SyntaxError for non-literal
|
||||||
|
# strings, but also TypeError/RecursionError on malformed input
|
||||||
|
# (e.g. unhashable dict keys); catch broadly to avoid crashing
|
||||||
|
# startup, and fall back to treating the value as a plain string.
|
||||||
if value.lower() == "false":
|
if value.lower() == "false":
|
||||||
config[name] = False
|
config[name] = False
|
||||||
elif value.lower() == "true":
|
elif value.lower() == "true":
|
||||||
|
|||||||
Reference in New Issue
Block a user