diff --git a/lib/core/common.py b/lib/core/common.py index 11bd5723c..53b425af4 100755 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1930,7 +1930,7 @@ def getFileItems(filename, commentPrefix='#', unicode_=True, lowercase=False, un retVal[line] = True else: retVal.append(line) - except (IOError, OSError), ex: + except (IOError, OSError, MemoryError), ex: errMsg = "something went wrong while trying " errMsg += "to read the content of file '%s' ('%s')" % (filename, ex) raise SqlmapSystemException(errMsg) diff --git a/lib/core/option.py b/lib/core/option.py index d0a3af309..986e1b080 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -90,6 +90,7 @@ from lib.core.exception import SqlmapMissingMandatoryOptionException from lib.core.exception import SqlmapMissingPrivileges from lib.core.exception import SqlmapSilentQuitException from lib.core.exception import SqlmapSyntaxException +from lib.core.exception import SqlmapSystemException from lib.core.exception import SqlmapUnsupportedDBMSException from lib.core.exception import SqlmapUserQuitException from lib.core.log import FORMATTER @@ -361,9 +362,14 @@ def _feedTargetsDict(reqFile, addedTargetUrls): kb.targets.add((url, method, data, cookie, tuple(headers))) addedTargetUrls.add(url) - fp = openFile(reqFile, "rb") - - content = fp.read() + checkFile(reqFile) + try: + with openFile(reqFile, "rb") as f: + content = f.read() + except (IOError, OSError, MemoryError), ex: + errMsg = "something went wrong while trying " + errMsg += "to read the content of file '%s' ('%s')" % (reqFile, ex) + raise SqlmapSystemException(errMsg) if conf.scope: logger.info("using regular expression '%s' for filtering targets" % conf.scope)