Minor update

This commit is contained in:
Miroslav Štampar 2026-06-21 23:30:52 +02:00
parent 9d8c1021f3
commit 46fc5acbfc
4 changed files with 53 additions and 7 deletions

View file

@ -186,10 +186,10 @@ c1a9edb894033f1cef0a15a05cca196f816df3465444134af171870dedbe1538 lib/core/optio
ccc4a717e887652b1fcce073d9409d9c59a3b28548c703a9e453d15845f90cd7 lib/core/patch.py
49c0fa7e3814dfda610d665ee02b12df299b28bc0b6773815b4395514ddf8dec lib/core/profiling.py
03db48f02c3d07a047ddb8fe33a757b6238867352d8ddda2a83e4fec09a98d04 lib/core/readlineng.py
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
9bf174058f15d14e24e94f9aaf42df045119d3617c6c54bd2f3af79b462f331d lib/core/replication.py
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
82767887306a66ba4b1b2c254068225196f3adb434bfac2929a123c51fdd45f8 lib/core/settings.py
3f62e7d98fb47950f6c9ff99386cb9ae346f7d64e2b0ed2c85cf9d394a2c6c69 lib/core/settings.py
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
70ea3768f1b3062b22d20644df41c86238157ec80dd43da40545c620714273c6 lib/core/target.py
@ -602,7 +602,7 @@ cde0bea1263ae857561f91ed2bd515e972b716743f017d31b1718a8546c72759 tests/test_pag
4bac34af2abddce003756d6776e89b2fda220bb7603ef3761f4f37ee29f9c369 tests/test_payload_marking.py
6bfc8201724078bd9d6d559916ef73c9ff97e19b0f2948f37e588a49b027795f tests/test_payloads_structure.py
a6d013104601c0414628aff3d8b5b69bee3e6733781d8f8da880457d8b44bd3a tests/test_property.py
5c95e7863190e440234f231864fb1219c35207132762858cc95181c57086bafc tests/test_replication.py
2dfefb4bfaee3868152835502ec43da317c4f274b1d55cd2ef21e4f7390c9bea tests/test_replication.py
67a5241aeebc20eb1c20cfc490422a59af5179040824e5731bd785db2e6bf750 tests/test_report.py
cec98d72992c0799229a780fa7f0d7f3fb01ec2d708187ce0e4a05c8612f291b tests/test_safe2bin.py
a1c6cda1e5b483f61e6a4f8ddd0b06a15ddaa3fd2119bfb9dbd9cc970d7a751d tests/test_settings_regex.py

View file

@ -23,8 +23,11 @@ class Replication(object):
"""
def __init__(self, dbpath):
self.dbpath = dbpath
self.connection = None
self.cursor = None
try:
self.dbpath = dbpath
self.connection = sqlite3.connect(dbpath)
self.connection.isolation_level = None
self.cursor = self.connection.cursor()
@ -120,8 +123,17 @@ class Replication(object):
return Replication.Table(parent=self, name=tblname, columns=columns, typeless=typeless)
def __del__(self):
self.cursor.close()
self.connection.close()
try:
if self.cursor is not None:
self.cursor.close()
except Exception:
pass
try:
if self.connection is not None:
self.connection.close()
except Exception:
pass
# sqlite data types
NULL = DataType('NULL')

View file

@ -20,7 +20,7 @@ from lib.core.enums import OS
from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.10.6.139"
VERSION = "1.10.6.140"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View file

@ -23,6 +23,8 @@ from _testutils import bootstrap
bootstrap()
from lib.core.replication import Replication
from lib.core.exception import SqlmapConnectionException
from lib.core.exception import SqlmapValueException
class _ReplCase(unittest.TestCase):
@ -83,5 +85,37 @@ class TestCreateInsertSelect(_ReplCase):
self.assertEqual(t2.select(), [])
class TestInsertColumnMismatch(_ReplCase):
def test_wrong_column_count_raises(self):
t = self.rep.createTable("c", [("a", self.rep.INTEGER), ("b", self.rep.TEXT)])
# too few / too many values must be rejected (not silently mis-inserted)
self.assertRaises(SqlmapValueException, t.insert, [1])
self.assertRaises(SqlmapValueException, t.insert, [1, "x", "extra"])
# the matching count still works
t.insert([1, "x"])
self.assertEqual(t.select(), [(1, "x")])
class TestInitFailure(unittest.TestCase):
"""A failed open (e.g. unwritable path) must raise cleanly and the partially
constructed object must be safe to finalize (no AttributeError in __del__)."""
def _bad_path(self):
# a database file inside a directory that does not exist => connect fails
return os.path.join(tempfile.gettempdir(), "sqlmap_no_such_dir_%d" % os.getpid(), "x.sqlite")
def test_bad_path_raises(self):
self.assertRaises(SqlmapConnectionException, Replication, self._bad_path())
def test_del_safe_after_failed_init(self):
obj = Replication.__new__(Replication)
self.assertRaises(SqlmapConnectionException, obj.__init__, self._bad_path())
# connection/cursor must be initialized even when connect() fails ...
self.assertIsNone(obj.connection)
self.assertIsNone(obj.cursor)
# ... so finalization is a no-op rather than raising
obj.__del__()
if __name__ == "__main__":
unittest.main(verbosity=2)