mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
Python: Add taint for StringIO and BytesIO
This commit is contained in:
committed by
Rasmus Wriedt Larsen
parent
57b9780428
commit
769f5691d0
47
python/ql/test/library-tests/frameworks/stdlib/io_test.py
Normal file
47
python/ql/test/library-tests/frameworks/stdlib/io_test.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from io import StringIO, BytesIO
|
||||
|
||||
TAINTED_STRING = "TS"
|
||||
TAINTED_BYTES = b"TB"
|
||||
|
||||
def ensure_tainted(*args):
|
||||
print("ensure_tainted")
|
||||
for arg in args:
|
||||
print("", repr(arg))
|
||||
|
||||
|
||||
def test_stringio():
|
||||
ts = TAINTED_STRING
|
||||
|
||||
x = StringIO()
|
||||
x.write(ts)
|
||||
x.seek(0)
|
||||
|
||||
ensure_tainted(
|
||||
StringIO(ts), # $ tainted
|
||||
StringIO(initial_value=ts), # $ tainted
|
||||
x, # $ tainted
|
||||
|
||||
x.read(), # $ tainted
|
||||
StringIO(ts).read(), # $ tainted
|
||||
)
|
||||
|
||||
|
||||
def test_bytesio():
|
||||
tb = TAINTED_BYTES
|
||||
|
||||
x = BytesIO()
|
||||
x.write(tb)
|
||||
x.seek(0)
|
||||
|
||||
ensure_tainted(
|
||||
BytesIO(tb), # $ tainted
|
||||
BytesIO(initial_bytes=tb), # $ tainted
|
||||
x, # $ tainted
|
||||
|
||||
x.read(), # $ tainted
|
||||
BytesIO(tb).read(), # $ tainted
|
||||
)
|
||||
|
||||
|
||||
test_stringio()
|
||||
test_bytesio()
|
||||
Reference in New Issue
Block a user