@@ -40,6 +40,7 @@ class WebSocketException(Exception):
4040from lib .core .common import getHeader
4141from lib .core .common import getHostHeader
4242from lib .core .common import getRequestHeader
43+ from lib .core .common import getSafeExString
4344from lib .core .common import getUnicode
4445from lib .core .common import logHTTPTraffic
4546from lib .core .common import pushValue
@@ -497,22 +498,22 @@ class _(dict):
497498 if hasattr (conn .fp , '_sock' ):
498499 conn .fp ._sock .close ()
499500 conn .close ()
500- except Exception , msg :
501- warnMsg = "problem occurred during connection closing ('%s')" % msg
501+ except Exception , ex :
502+ warnMsg = "problem occurred during connection closing ('%s')" % getSafeExString ( ex )
502503 logger .warn (warnMsg )
503504
504- except urllib2 .HTTPError , e :
505+ except urllib2 .HTTPError , ex :
505506 page = None
506507 responseHeaders = None
507508
508509 try :
509- page = e .read () if not skipRead else None
510- responseHeaders = e .info ()
511- responseHeaders [URI_HTTP_HEADER ] = e .geturl ()
510+ page = ex .read () if not skipRead else None
511+ responseHeaders = ex .info ()
512+ responseHeaders [URI_HTTP_HEADER ] = ex .geturl ()
512513 page = decodePage (page , responseHeaders .get (HTTP_HEADER .CONTENT_ENCODING ), responseHeaders .get (HTTP_HEADER .CONTENT_TYPE ))
513514 except socket .timeout :
514515 warnMsg = "connection timed out while trying "
515- warnMsg += "to get error page information (%d)" % e .code
516+ warnMsg += "to get error page information (%d)" % ex .code
516517 logger .warn (warnMsg )
517518 return None , None , None
518519 except KeyboardInterrupt :
@@ -522,13 +523,13 @@ class _(dict):
522523 finally :
523524 page = page if isinstance (page , unicode ) else getUnicode (page )
524525
525- code = e .code
526+ code = ex .code
526527
527528 kb .originalCode = kb .originalCode or code
528529 threadData .lastHTTPError = (threadData .lastRequestUID , code )
529530 kb .httpErrorCodes [code ] = kb .httpErrorCodes .get (code , 0 ) + 1
530531
531- status = getUnicode (e .msg )
532+ status = getUnicode (ex .msg )
532533 responseMsg += "[#%d] (%d %s):\n " % (threadData .lastRequestUID , code , status )
533534
534535 if responseHeaders :
@@ -545,23 +546,23 @@ class _(dict):
545546
546547 logger .log (CUSTOM_LOGGING .TRAFFIC_IN , responseMsg )
547548
548- if e .code == httplib .UNAUTHORIZED and not conf .ignore401 :
549+ if ex .code == httplib .UNAUTHORIZED and not conf .ignore401 :
549550 errMsg = "not authorized, try to provide right HTTP "
550551 errMsg += "authentication type and valid credentials (%d)" % code
551552 raise SqlmapConnectionException (errMsg )
552- elif e .code == httplib .NOT_FOUND :
553+ elif ex .code == httplib .NOT_FOUND :
553554 if raise404 :
554555 errMsg = "page not found (%d)" % code
555556 raise SqlmapConnectionException (errMsg )
556557 else :
557558 debugMsg = "page not found (%d)" % code
558559 singleTimeLogMessage (debugMsg , logging .DEBUG )
559560 processResponse (page , responseHeaders )
560- elif e .code == httplib .GATEWAY_TIMEOUT :
561+ elif ex .code == httplib .GATEWAY_TIMEOUT :
561562 if ignoreTimeout :
562563 return None , None , None
563564 else :
564- warnMsg = "unable to connect to the target URL (%d - %s)" % (e .code , httplib .responses [e .code ])
565+ warnMsg = "unable to connect to the target URL (%d - %s)" % (ex .code , httplib .responses [ex .code ])
565566 if threadData .retriesCount < conf .retries and not kb .threadException :
566567 warnMsg += ". sqlmap is going to retry the request"
567568 logger .critical (warnMsg )
@@ -575,7 +576,7 @@ class _(dict):
575576 debugMsg = "got HTTP error code: %d (%s)" % (code , status )
576577 logger .debug (debugMsg )
577578
578- except (urllib2 .URLError , socket .error , socket .timeout , httplib .HTTPException , struct .error , ProxyError , SqlmapCompressionException , WebSocketException ), e :
579+ except (urllib2 .URLError , socket .error , socket .timeout , httplib .HTTPException , struct .error , ProxyError , SqlmapCompressionException , WebSocketException ):
579580 tbMsg = traceback .format_exc ()
580581
581582 if "no host given" in tbMsg :
@@ -718,7 +719,7 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
718719 payload = function (payload = payload , headers = auxHeaders )
719720 except Exception , ex :
720721 errMsg = "error occurred while running tamper "
721- errMsg += "function '%s' ('%s')" % (function .func_name , ex )
722+ errMsg += "function '%s' ('%s')" % (function .func_name , getSafeExString ( ex ) )
722723 raise SqlmapGenericException (errMsg )
723724
724725 if not isinstance (payload , basestring ):
0 commit comments