From 18cece1fe994a93cdfd6bdfc4b9b01979c950c32 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 1 Oct 2012 19:19:46 -0400 Subject: [PATCH] Better protection against malformed JSON. --- irkerd | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/irkerd b/irkerd index 9207ae1..44aca0b 100755 --- a/irkerd +++ b/irkerd @@ -363,11 +363,6 @@ class Irker: def handle(self, line): "Perform a JSON relay request." try: - # Without this guard, a line consisting of a thousand '[' chars - # can crash irker by inducing the JSON parser to blow Python's - # recursion stack. - if line.count("[") > 256 or line.count("{") > 256: - raise ValueError request = json.loads(line.strip()) if type(request) != type({}): self.logerr("request in tot a JSON dictionary: %s" % repr(request)) @@ -419,6 +414,8 @@ class Irker: del self.servers[oldest] except ValueError: self.logerr("can't recognize JSON on input: %s" % repr(line)) + except RuntimeException: + self.logerr("wildly malformed JSON blew the parser stack.") class IrkerTCPHandler(SocketServer.StreamRequestHandler): def handle(self): -- 2.26.2