mirror of
				https://github.com/sqlmapproject/sqlmap.git
				synced 2025-11-04 01:47:37 +03:00 
			
		
		
		
	Patch for an Issue #976
This commit is contained in:
		
							parent
							
								
									8cd40f8917
								
							
						
					
					
						commit
						605b126758
					
				| 
						 | 
				
			
			@ -861,7 +861,7 @@ def dataToOutFile(filename, data):
 | 
			
		|||
        retVal = os.path.join(conf.filePath, filePathToSafeString(filename))
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            with codecs.open(retVal, "wb", UNICODE_ENCODING) as f:
 | 
			
		||||
            with openFile(retVal, "wb") as f:
 | 
			
		||||
                f.write(data)
 | 
			
		||||
        except IOError, ex:
 | 
			
		||||
            errMsg = "something went wrong while trying to write "
 | 
			
		||||
| 
						 | 
				
			
			@ -1813,7 +1813,7 @@ def readCachedFileContent(filename, mode='rb'):
 | 
			
		|||
        with kb.locks.cache:
 | 
			
		||||
            if filename not in kb.cache.content:
 | 
			
		||||
                checkFile(filename)
 | 
			
		||||
                with codecs.open(filename, mode, UNICODE_ENCODING) as f:
 | 
			
		||||
                with openFile(filename, mode) as f:
 | 
			
		||||
                    kb.cache.content[filename] = f.read()
 | 
			
		||||
 | 
			
		||||
    return kb.cache.content[filename]
 | 
			
		||||
| 
						 | 
				
			
			@ -1878,7 +1878,7 @@ def initCommonOutputs():
 | 
			
		|||
    kb.commonOutputs = {}
 | 
			
		||||
    key = None
 | 
			
		||||
 | 
			
		||||
    with codecs.open(paths.COMMON_OUTPUTS, 'r', UNICODE_ENCODING) as f:
 | 
			
		||||
    with openFile(paths.COMMON_OUTPUTS, 'r') as f:
 | 
			
		||||
        for line in f.readlines():  # xreadlines doesn't return unicode strings when codec.open() is used
 | 
			
		||||
            if line.find('#') != -1:
 | 
			
		||||
                line = line[:line.find('#')]
 | 
			
		||||
| 
						 | 
				
			
			@ -1905,7 +1905,7 @@ def getFileItems(filename, commentPrefix='#', unicode_=True, lowercase=False, un
 | 
			
		|||
    checkFile(filename)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        with codecs.open(filename, 'r', UNICODE_ENCODING, errors="ignore") if unicode_ else open(filename, 'r') as f:
 | 
			
		||||
        with openFile(filename, 'r', errors="ignore") if unicode_ else open(filename, 'r') as f:
 | 
			
		||||
            for line in (f.readlines() if unicode_ else f.xreadlines()):  # xreadlines doesn't return unicode strings when codec.open() is used
 | 
			
		||||
                if commentPrefix:
 | 
			
		||||
                    if line.find(commentPrefix) != -1:
 | 
			
		||||
| 
						 | 
				
			
			@ -2822,13 +2822,13 @@ def showHttpErrorCodes():
 | 
			
		|||
          for code, count in kb.httpErrorCodes.items())
 | 
			
		||||
        logger.warn(warnMsg)
 | 
			
		||||
 | 
			
		||||
def openFile(filename, mode='r'):
 | 
			
		||||
def openFile(filename, mode='r', encoding=UNICODE_ENCODING, errors="replace"):
 | 
			
		||||
    """
 | 
			
		||||
    Returns file handle of a given filename
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        return codecs.open(filename, mode, UNICODE_ENCODING, "replace")
 | 
			
		||||
        return codecs.open(filename, mode, encoding, errors)
 | 
			
		||||
    except IOError:
 | 
			
		||||
        errMsg = "there has been a file opening error for filename '%s'. " % filename
 | 
			
		||||
        errMsg += "Please check %s permissions on a file " % ("write" if \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,7 +87,7 @@ class Dump(object):
 | 
			
		|||
    def setOutputFile(self):
 | 
			
		||||
        self._outputFile = os.path.join(conf.outputPath, "log")
 | 
			
		||||
        try:
 | 
			
		||||
            self._outputFP = codecs.open(self._outputFile, "ab" if not conf.flushSession else "wb", UNICODE_ENCODING)
 | 
			
		||||
            self._outputFP = openFile(self._outputFile, "ab" if not conf.flushSession else "wb")
 | 
			
		||||
        except IOError, ex:
 | 
			
		||||
            errMsg = "error occurred while opening log file ('%s')" % ex
 | 
			
		||||
            raise SqlmapGenericException(errMsg)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,7 @@ from ConfigParser import MissingSectionHeaderError
 | 
			
		|||
from ConfigParser import ParsingError
 | 
			
		||||
 | 
			
		||||
from lib.core.common import checkFile
 | 
			
		||||
from lib.core.common import openFile
 | 
			
		||||
from lib.core.common import unArrayizeValue
 | 
			
		||||
from lib.core.common import UnicodeRawConfigParser
 | 
			
		||||
from lib.core.data import conf
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +66,7 @@ def configFileParser(configFile):
 | 
			
		|||
    logger.debug(debugMsg)
 | 
			
		||||
 | 
			
		||||
    checkFile(configFile)
 | 
			
		||||
    configFP = codecs.open(configFile, "rb", UNICODE_ENCODING)
 | 
			
		||||
    configFP = openFile(configFile, "rb")
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        config = UnicodeRawConfigParser()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ import time
 | 
			
		|||
from lib.core.common import clearConsoleLine
 | 
			
		||||
from lib.core.common import dataToStdout
 | 
			
		||||
from lib.core.common import findPageForms
 | 
			
		||||
from lib.core.common import openFile
 | 
			
		||||
from lib.core.common import readInput
 | 
			
		||||
from lib.core.common import safeCSValue
 | 
			
		||||
from lib.core.common import singleTimeWarnMessage
 | 
			
		||||
| 
						 | 
				
			
			@ -170,7 +171,7 @@ def storeResultsToFile(results):
 | 
			
		|||
        infoMsg = "writing crawling results to a temporary file '%s' " % filename
 | 
			
		||||
        logger.info(infoMsg)
 | 
			
		||||
 | 
			
		||||
        with codecs.open(filename, "w+b", UNICODE_ENCODING) as f:
 | 
			
		||||
        with openFile(filename, "w+b") as f:
 | 
			
		||||
            if conf.forms:
 | 
			
		||||
                f.write("URL,POST\n")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user