From: <Blu...@us...> - 2009-12-15 20:56:55
|
Revision: 317 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=317&view=rev Author: BlueWolf_ Date: 2009-12-15 20:56:45 +0000 (Tue, 15 Dec 2009) Log Message: ----------- It now catches crashes from the parser Modified Paths: -------------- trunk/server/core/callback.py trunk/server/core/server.py Modified: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py 2009-12-14 21:23:28 UTC (rev 316) +++ trunk/server/core/callback.py 2009-12-15 20:56:45 UTC (rev 317) @@ -69,6 +69,10 @@ * "duplicate" - Another client has logged in on this account. This connection has been kicked + * "crash" - A crash in the parser happened. This + could be because of malicious data was + send. Use callback.debug_traceback to + get the precise error This is a placeholder. If you want to catch this event, @@ -128,4 +132,19 @@ overwrite this in your own callback. """ pass + + + def debug_crash(self, tracback): + """ + Usefull for debugging. Normally, when the parser (our any code + in the parser, like the callback) crashes, the connection will + be kicked and the error will be ignored. If you want to know the + precise error, use this function to get the trackback + + traceback: + A string... with a traceback, duh :-) + + This is a placeholder. If you want to catch this event, + overwrite this in your own callback. + """ Modified: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py 2009-12-14 21:23:28 UTC (rev 316) +++ trunk/server/core/server.py 2009-12-15 20:56:45 UTC (rev 317) @@ -15,7 +15,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import simplejson, socket, threading, time, md5, random +import simplejson, socket, threading, time, md5, random, sys from parser import Parser from database import Database import rsa @@ -201,7 +201,25 @@ def __repr__(self): return '<Client(%s)>'%self.__cid + + + def __parser_crash(self): + """ + Will create a traceback and call the callback + """ + #Get some debugging info + et, ev, tb = sys.exc_info() + traceback = "" + while tb: + co = tb.tb_frame.f_code + traceback += str(co.co_filename) + ':' + \ + str(tb.tb_lineno) + '\n' + tb = tb.tb_next + traceback += ev.__class__.__name__ + ': ' + str(ev) + + self.__call.debug_crash(traceback) + def run(self): """ Used by threading, not for external usage. @@ -242,8 +260,16 @@ data = data[:-1] for msg in data: - self.__parser(self.__cid, + try: + self.__parser(self.__cid, simplejson.loads(msg)) + except Exception, Er: + self.__parser_crash() + + # Kick connection + self.send("disconnect", + {"reason":"crash"}) + self.close("crash") def close(self, reason = "manual"): """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |