Skip to content

Commit 86630f1

Browse files
committed
Python: Handle readline, readlines for ExternalFileObject
1 parent 7385ea5 commit 86630f1

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

python/ql/src/semmle/python/security/strings/External.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ class ExternalFileObject extends TaintKind {
191191
TaintKind getValue() { result = valueKind }
192192

193193
override TaintKind getTaintOfMethodResult(string name) {
194-
name = "read" and result = this.getValue()
194+
name in ["read", "readline"] and result = this.getValue()
195+
or
196+
name = "readlines" and result.(SequenceKind).getItem() = this.getValue()
195197
}
196198
}
197199

python/ql/test/library-tests/taint/strings/TestStep.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
| Taint file[externally controlled string] | test.py:72 | test.py:72:20:72:31 | TAINTED_FILE | | --> | Taint file[externally controlled string] | test.py:77 | test.py:77:9:77:20 | tainted_file | |
6969
| Taint file[externally controlled string] | test.py:72 | test.py:72:20:72:31 | TAINTED_FILE | | --> | Taint file[externally controlled string] | test.py:78 | test.py:78:27:78:38 | tainted_file | |
7070
| Taint file[externally controlled string] | test.py:75 | test.py:75:9:75:20 | tainted_file | | --> | Taint externally controlled string | test.py:75 | test.py:75:9:75:27 | Attribute() | |
71+
| Taint file[externally controlled string] | test.py:76 | test.py:76:9:76:20 | tainted_file | | --> | Taint externally controlled string | test.py:76 | test.py:76:9:76:31 | Attribute() | |
72+
| Taint file[externally controlled string] | test.py:77 | test.py:77:9:77:20 | tainted_file | | --> | Taint [externally controlled string] | test.py:77 | test.py:77:9:77:32 | Attribute() | |
7173
| Taint json[externally controlled string] | test.py:6 | test.py:6:20:6:45 | Attribute() | | --> | Taint json[externally controlled string] | test.py:7 | test.py:7:9:7:20 | tainted_json | |
7274
| Taint json[externally controlled string] | test.py:7 | test.py:7:9:7:20 | tainted_json | | --> | Taint externally controlled string | test.py:7 | test.py:7:9:7:25 | Subscript | |
7375
| Taint json[externally controlled string] | test.py:7 | test.py:7:9:7:20 | tainted_json | | --> | Taint json[externally controlled string] | test.py:7 | test.py:7:9:7:25 | Subscript | |

python/ql/test/library-tests/taint/strings/TestTaint.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
| test.py:69 | test_urlsplit_urlparse | urlsplit_res | [externally controlled string] |
2525
| test.py:74 | test_tainted_file | tainted_file | file[externally controlled string] |
2626
| test.py:75 | test_tainted_file | Attribute() | externally controlled string |
27-
| test.py:76 | test_tainted_file | Attribute() | NO TAINT |
28-
| test.py:77 | test_tainted_file | Attribute() | NO TAINT |
27+
| test.py:76 | test_tainted_file | Attribute() | externally controlled string |
28+
| test.py:77 | test_tainted_file | Attribute() | [externally controlled string] |
2929
| test.py:78 | test_tainted_file | ListComp | NO TAINT |

0 commit comments

Comments
 (0)