Permalink
Browse files

protect kernelapp/qtconsole from invalid connection files

(clean error/exit, rather than crash)

also use stdlib json to load connection file, not zmq.jsonapi, which can be
jsonlib2, which will return Longs, causing TraitError.
  • Loading branch information...
1 parent a1987bd commit 64e90b1e867da8e6d20bc44f1fc0385a87e37898 @minrk minrk committed Oct 14, 2011
Showing with 12 additions and 5 deletions.
  1. +6 −2 IPython/frontend/qt/console/qtconsoleapp.py
  2. +6 −3 IPython/zmq/kernelapp.py
@@ -17,14 +17,14 @@
#-----------------------------------------------------------------------------
# stdlib imports
+import json
import os
import signal
import sys
# System library imports
from IPython.external.qt import QtGui
from pygments.styles import get_all_styles
-from zmq.utils import jsonapi as json
# Local imports
from IPython.config.application import boolean_flag
@@ -373,7 +373,11 @@ def init_connection_file(self):
# should load_connection_file only be used for existing?
# as it is now, this allows reusing ports if an existing
# file is requested
- self.load_connection_file()
+ try:
+ self.load_connection_file()
+ except Exception:
+ self.log.error("Failed to load connection file: %r", self.connection_file, exc_info=True)
+ self.exit(1)
def load_connection_file(self):
"""load ip/port/hmac config from JSON connection file"""
View
@@ -16,12 +16,12 @@
#-----------------------------------------------------------------------------
# Standard library imports.
+import json
import os
import sys
# System library imports.
import zmq
-from zmq.utils import jsonapi as json
# IPython imports.
from IPython.core.ultratb import FormattedTB
@@ -192,8 +192,11 @@ def write_connection_file(self):
def init_connection_file(self):
if not self.connection_file:
self.connection_file = "kernel-%s.json"%os.getpid()
-
- self.load_connection_file()
+ try:
+ self.load_connection_file()
+ except Exception:
+ self.log.error("Failed to load connection file: %r", self.connection_file, exc_info=True)
+ self.exit(1)
def init_sockets(self):
# Create a context, a session, and the kernel sockets.

0 comments on commit 64e90b1

Please sign in to comment.