Skip to content

Commit 6224344

Browse files
committed
Minor update regarding the #6120
1 parent 7cbbbaf commit 6224344

3 files changed

Lines changed: 89 additions & 6 deletions

File tree

‎lib/core/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.9.10"
23+
VERSION = "1.10.9.11"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

‎sqlmap.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,14 @@ def main():
559559
raise SystemExit
560560

561561
elif (sys._jit.is_enabled() if hasattr(sys, "_jit") else os.environ.get("PYTHON_JIT") == '1'):
562-
errMsg = "the experimental Python JIT compiler appears to be turned on. There are known cases of it "
563-
errMsg += "producing bogus errors inside otherwise correct code (e.g. a built-in function resolving "
564-
errMsg += "to an unrelated object). Please rerun with it turned off (e.g. 'PYTHON_JIT=0') and report "
565-
errMsg += "the problem only if it still occurs "
566-
errMsg += "(Reference: 'https://github.com/sqlmapproject/sqlmap/issues/6117')"
562+
errMsg = "the experimental Python JIT compiler is turned on. CPython has an open defect where "
563+
errMsg += "the tier-2 optimizer runs the wrong instruction stream against a correct frame, raising "
564+
errMsg += "exceptions that the executed code cannot produce "
565+
errMsg += "(Reference: 'https://github.com/python/cpython/issues/156319'). Please rerun with it "
566+
errMsg += "turned off (e.g. 'PYTHON_JIT=0') and report the problem only if it still occurs"
567567
logger.critical(errMsg)
568+
print()
569+
dataToStdout(excMsg)
568570
raise SystemExit
569571

570572
for match in re.finditer(r'File "(.+?)", line', excMsg):

‎tests/test_jit_guard.py‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
5+
See the file 'LICENSE' for copying permission
6+
7+
The last branch of main()'s unhandled-exception chain in sqlmap.py: when the
8+
experimental Python JIT is turned on, a crash gets the tier-2 advisory (Reference:
9+
'https://github.com/python/cpython/issues/156319') instead of the automatic
10+
issue-creation prompt - but the traceback is still printed, so a genuine sqlmap
11+
bug is not swallowed.
12+
13+
Driven through a subprocess because it is main()'s own except chain under test.
14+
"""
15+
16+
import os
17+
import subprocess
18+
import sys
19+
import unittest
20+
21+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
22+
23+
# forces a crash inside init(), i.e. the same place #6117 landed, without needing a target.
24+
# codeIsModified() is neutralized because its branch sits earlier in the chain and would
25+
# otherwise win on any working tree with uncommitted edits (or a stale txt/checksum.md5).
26+
DRIVER = """
27+
import sys
28+
sys.path.insert(0, %r)
29+
sys.argv = ["sqlmap.py", "-u", "http://127.0.0.1/?id=1", "--batch"]
30+
import sqlmap
31+
import lib.core.option
32+
sqlmap.codeIsModified = lambda: False
33+
lib.core.option.loadPayloads = lambda: "a" < 128
34+
sqlmap.main()
35+
""" % ROOT
36+
37+
ADVISORY = "experimental Python JIT compiler is turned on"
38+
TRACEBACK = "TypeError"
39+
PROMPT = "automatically create a new (anonymized) issue"
40+
41+
42+
def _run(jit):
43+
env = dict(os.environ)
44+
env["PYTHON_JIT"] = jit
45+
proc = subprocess.Popen([sys.executable, "-c", DRIVER], cwd=ROOT, env=env,
46+
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
47+
stderr=subprocess.STDOUT)
48+
out = proc.communicate(input=b"")[0]
49+
return out.decode("utf-8", "replace")
50+
51+
52+
def _jitEnabled(jit):
53+
"""Whether the interpreter actually honours PYTHON_JIT=<jit> (build-dependent)."""
54+
code = "import sys, os; print(sys._jit.is_enabled() if hasattr(sys, '_jit') else os.environ.get('PYTHON_JIT') == '1')"
55+
env = dict(os.environ)
56+
env["PYTHON_JIT"] = jit
57+
return subprocess.check_output([sys.executable, "-c", code], env=env).strip() == b"True"
58+
59+
60+
class TestJitGuard(unittest.TestCase):
61+
def test_advisory_replaces_issue_prompt_but_keeps_traceback(self):
62+
if not _jitEnabled('1'):
63+
self.skipTest("interpreter does not report the JIT as enabled")
64+
65+
out = _run('1')
66+
self.assertIn(ADVISORY, out)
67+
self.assertIn(TRACEBACK, out) # a real bug must still be visible in full
68+
self.assertNotIn(PROMPT, out) # ... but not auto-filed while the JIT is on
69+
70+
def test_normal_path_is_untouched_without_jit(self):
71+
if _jitEnabled('0'):
72+
self.skipTest("JIT stays enabled with PYTHON_JIT=0 on this build")
73+
74+
out = _run('0')
75+
self.assertNotIn(ADVISORY, out)
76+
self.assertIn(TRACEBACK, out)
77+
self.assertIn(PROMPT, out)
78+
79+
80+
if __name__ == "__main__":
81+
unittest.main()

0 commit comments

Comments
 (0)