From c24f1cc07c9f79e7bc6a2636a67cf77af9c16be8 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 6 Apr 2010 14:59:31 +0000 Subject: [PATCH] some update --- lib/utils/timeout.py | 12 ++++++++---- plugins/dbms/access/connector.py | 10 +++++----- plugins/dbms/firebird/connector.py | 10 +++++----- plugins/dbms/mssqlserver/connector.py | 10 +++++----- plugins/dbms/mysql/connector.py | 10 +++++----- plugins/dbms/oracle/connector.py | 11 ++++++----- plugins/dbms/postgresql/connector.py | 11 ++++++----- plugins/dbms/sqlite/connector.py | 10 +++++----- 8 files changed, 45 insertions(+), 39 deletions(-) diff --git a/lib/utils/timeout.py b/lib/utils/timeout.py index f4db06ffb..126af4861 100644 --- a/lib/utils/timeout.py +++ b/lib/utils/timeout.py @@ -2,22 +2,26 @@ import threading -def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None): +def timeout(func, args=(), kwargs={}, duration=1, default=None): class InterruptableThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) + self.exceeded = False + self.exceptionMsg = None self.result = None def run(self): try: self.result = func(*args, **kwargs) - except: + except Exception, msg: + self.exceptionMsg = msg self.result = default thread = InterruptableThread() thread.start() - thread.join(timeout_duration) - if thread.isAlive(): + thread.join(duration) + self.exceeded = thread.isAlive() + if self.exceeded: return default else: return thread.result diff --git a/plugins/dbms/access/connector.py b/plugins/dbms/access/connector.py index cfddd0e1d..e07858634 100644 --- a/plugins/dbms/access/connector.py +++ b/plugins/dbms/access/connector.py @@ -30,6 +30,7 @@ except ImportError, _: from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -60,11 +61,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except pyodbc.ProgrammingError, msg: - logger.log(8, msg[1]) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg[1]) + return retVal def execute(self, query): logger.debug(query) diff --git a/plugins/dbms/firebird/connector.py b/plugins/dbms/firebird/connector.py index 1e0632a34..71df93785 100644 --- a/plugins/dbms/firebird/connector.py +++ b/plugins/dbms/firebird/connector.py @@ -30,6 +30,7 @@ except ImportError, _: from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -59,11 +60,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except kinterbasdb.OperationalError, msg: - logger.log(8, msg[1]) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg[1]) + return retVal def execute(self, query): logger.debug(query) diff --git a/plugins/dbms/mssqlserver/connector.py b/plugins/dbms/mssqlserver/connector.py index e17abe93a..990292c48 100644 --- a/plugins/dbms/mssqlserver/connector.py +++ b/plugins/dbms/mssqlserver/connector.py @@ -31,6 +31,7 @@ except ImportError, _: from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -63,11 +64,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except (pymssql.ProgrammingError, pymssql.OperationalError, _mssql.MssqlDatabaseException), msg: - logger.log(8, msg) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg) + return retVal def execute(self, query): logger.debug(query) diff --git a/plugins/dbms/mysql/connector.py b/plugins/dbms/mysql/connector.py index b5cf472d6..5c3bc099c 100644 --- a/plugins/dbms/mysql/connector.py +++ b/plugins/dbms/mysql/connector.py @@ -30,6 +30,7 @@ except ImportError, _: from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -59,11 +60,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except MySQLdb.ProgrammingError, msg: - logger.log(8, msg[1]) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg[1]) + return retVal def execute(self, query): logger.debug(query) diff --git a/plugins/dbms/oracle/connector.py b/plugins/dbms/oracle/connector.py index 06577673d..5d9bbc9ba 100644 --- a/plugins/dbms/oracle/connector.py +++ b/plugins/dbms/oracle/connector.py @@ -27,8 +27,10 @@ try: except ImportError, _: pass +from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -60,11 +62,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except cx_Oracle.InterfaceError, msg: - logger.log(8, msg) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg) + return retVal def execute(self, query): logger.debug(query) diff --git a/plugins/dbms/postgresql/connector.py b/plugins/dbms/postgresql/connector.py index 376d1876c..e8466f395 100644 --- a/plugins/dbms/postgresql/connector.py +++ b/plugins/dbms/postgresql/connector.py @@ -27,8 +27,10 @@ try: except ImportError, _: pass +from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -58,11 +60,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except psycopg2.ProgrammingError, msg: - logger.log(8, msg) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg) + return retVal def execute(self, query): logger.debug(query) diff --git a/plugins/dbms/sqlite/connector.py b/plugins/dbms/sqlite/connector.py index 9c4d34279..9bba1055f 100644 --- a/plugins/dbms/sqlite/connector.py +++ b/plugins/dbms/sqlite/connector.py @@ -30,6 +30,7 @@ except ImportError, _: from lib.core.data import conf from lib.core.data import logger from lib.core.exception import sqlmapConnectionException +from lib.utils.timeout import timeout from plugins.generic.connector import Connector as GenericConnector @@ -60,11 +61,10 @@ class Connector(GenericConnector): self.connected() def fetchall(self): - try: - return self.cursor.fetchall() - except sqlite3.OperationalError, msg: - logger.log(8, msg[0]) - return None + retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None) + if self.exceptionMsg: + logger.log(8, self.exceptionMsg[0]) + return retVal def execute(self, query): logger.debug(query)