Skip to content

Commit 300e3bd

Browse files
authored
Merge pull request #1057 from markshannon/python-fix-os-guard
Python: Fix up OsGuard class.
2 parents 57732ee + ef1c08e commit 300e3bd

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

python/ql/src/semmle/python/types/Version.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ class VersionGuard extends ConditionBlock {
9191
}
9292

9393
string os_name(StrConst s) {
94-
exists(string t |
94+
exists(string t |
9595
t = s.getText() |
96-
t = "Darwin" and result = "darwin"
96+
(t = "linux" or t = "linux2") and result = "Linux"
9797
or
98-
t = "Windows" and result = "win32"
98+
t = "win32" and result = "Windows"
9999
or
100-
t = "Linux" and result = "linux"
100+
t = "darwin" and result = "Darwin"
101101
or
102-
not t = "Darwin" and not t = "Windows" and not t = "Linux" and result = t
102+
not t = "linux" and not t = "linux2" and not t = "win32" and not t = "darwin" and result = t
103103
)
104104
}
105105

@@ -154,13 +154,13 @@ class OsGuard extends ConditionBlock {
154154

155155
OsGuard() {
156156
exists(OsTest t |
157-
PointsTo::points_to(this.getLastNode(), _, theBoolType(), t, _)
157+
PointsTo::points_to(this.getLastNode(), _, _, theBoolType(), t)
158158
)
159159
}
160160

161161
string getOs() {
162162
exists(OsTest t |
163-
PointsTo::points_to(this.getLastNode(), _, theBoolType(), t, _) and result = t.getOs()
163+
PointsTo::points_to(this.getLastNode(), _, _, theBoolType(), t) and result = t.getOs()
164164
)
165165
}
166166

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| 34 | BasicBlock | Linux |
2+
| 68 | BasicBlock | Windows |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
import python
3+
import semmle.python.types.Version
4+
5+
from OsGuard og, Location l
6+
where l = og.getLastNode().getLocation() and
7+
l.getFile().getName().matches("%test.py")
8+
select l.getStartLine(), og.toString(), og.getOs()

python/ql/test/library-tests/PointsTo/version/test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
os_test = sys.platform == "linux"
14+
os_test = sys.platform == "win32"
1515
version_test = sys.version_info < (3,)
1616

1717
from module import os_test as t2
@@ -64,3 +64,7 @@ def H(): pass
6464
#From problem_report
6565
Py2g = sys.version[0] < '3'
6666
Py3h = sys.version[0] >= '3'
67+
68+
if os_test:
69+
pass
70+

0 commit comments

Comments
 (0)