From c4426952ad5f2f48e4684d3a902e4a7a586545ce Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 6 Jul 2012 15:43:33 +1200 Subject: [PATCH] Protect against exceptions thrown by third-party view libraries. --- libmproxy/console/contentview.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index e64cb4fa3..a6e6ee91b 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -234,12 +234,7 @@ def view_urlencoded(hdrs, content, limit): def view_javascript(hdrs, content, limit): opts = jsbeautifier.default_options() opts.indent_size = 2 - try: - res = jsbeautifier.beautify(content[:limit], opts) - except: # pragma: no cover - # Bugs in jsbeautifier mean that it - # can throw arbitrary errors. - return None # pragma: no cover + res = jsbeautifier.beautify(content[:limit], opts) return "JavaScript", _view_text(res, len(content), limit) @@ -320,7 +315,11 @@ def get_content_view(viewmode, hdrItems, content, limit): content = decoded msg.append("[decoded %s]"%enc[0]) func = get_view_func(viewmode, hdrs, content) - ret = func(hdrs, content, limit) + try: + ret = func(hdrs, content, limit) + # Third-party viewers can fail in unexpected ways... + except: + ret = None if not ret: viewmode = VIEW_RAW ret = view_raw(hdrs, content, limit)