Skip to content

Commit 71d79ca

Browse files
committed
Add test for NUL byte in interactive mode
1 parent 0463fb7 commit 71d79ca

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Lib/test/test_cmd_line.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ def test_run_module_bug1764407(self):
201201
self.assertTrue(data.find(b'1 loop') != -1)
202202
self.assertTrue(data.find(b'__main__.Timer') != -1)
203203

204+
@support.cpython_only
205+
def test_null_byte_in_interactive_mode(self):
206+
# gh-140594: heap-buffer-underflow в PyOS_StdioReadline при \0 в интерактивном вводе
207+
env = os.environ.copy()
208+
env.pop('PYTHONSTARTUP', None)
209+
args = [sys.executable, '-I', '-S', '-q', '-i']
210+
p = subprocess.Popen(
211+
args,
212+
stdin=subprocess.PIPE,
213+
stdout=subprocess.PIPE,
214+
stderr=subprocess.STDOUT,
215+
)
216+
out, _ = p.communicate(b'\x00', timeout=10)
217+
self.assertEqual(
218+
p.returncode, 0,
219+
msg=f"Interpreter aborted on NUL input, output:\n{out[:500]!r}"
220+
)
221+
if out:
222+
self.assertNotIn(b'AddressSanitizer', out)
223+
self.assertNotIn(b'ERROR:', out)
224+
204225
def test_relativedir_bug46421(self):
205226
# Test `python -m unittest` with a relative directory beginning with ./
206227
# Note: We have to switch to the project's top module's directory, as per

0 commit comments

Comments
 (0)