Skip to content

Commit 9d63efe

Browse files
committed
Python: Set literals.
1 parent b9cce57 commit 9d63efe

File tree

4 files changed

+29
-89
lines changed

4 files changed

+29
-89
lines changed

python/ql/lib/semmle/python/concepts/CryptoAlgorithms.qll

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,35 @@
1515
*/
1616
private module AlgorithmNames {
1717
predicate isStrongHashingAlgorithm(string name) {
18-
name = "DSA" or
19-
name = "ED25519" or
20-
name = "ES256" or
21-
name = "ECDSA256" or
22-
name = "ES384" or
23-
name = "ECDSA384" or
24-
name = "ES512" or
25-
name = "ECDSA512" or
26-
name = "SHA2" or
27-
name = "SHA224" or
28-
name = "SHA256" or
29-
name = "SHA384" or
30-
name = "SHA512" or
31-
name = "SHA3" or
32-
name = "SHA3224" or
33-
name = "SHA3256" or
34-
name = "SHA3384" or
35-
name = "SHA3512"
18+
name =
19+
[
20+
"DSA", "ED25519", "ES256", "ECDSA256", "ES384", "ECDSA384", "ES512", "ECDSA512", "SHA2",
21+
"SHA224", "SHA256", "SHA384", "SHA512", "SHA3", "SHA3224", "SHA3256", "SHA3384", "SHA3512"
22+
]
3623
}
3724

3825
predicate isWeakHashingAlgorithm(string name) {
39-
name = "HAVEL128" or
40-
name = "MD2" or
41-
name = "MD4" or
42-
name = "MD5" or
43-
name = "PANAMA" or
44-
name = "RIPEMD" or
45-
name = "RIPEMD128" or
46-
name = "RIPEMD256" or
47-
name = "RIPEMD160" or
48-
name = "RIPEMD320" or
49-
name = "SHA0" or
50-
name = "SHA1"
26+
name =
27+
[
28+
"HAVEL128", "MD2", "MD4", "MD5", "PANAMA", "RIPEMD", "RIPEMD128", "RIPEMD256", "RIPEMD160",
29+
"RIPEMD320", "SHA0", "SHA1"
30+
]
5131
}
5232

5333
predicate isStrongEncryptionAlgorithm(string name) {
54-
name = "AES" or
55-
name = "AES128" or
56-
name = "AES192" or
57-
name = "AES256" or
58-
name = "AES512" or
59-
name = "RSA" or
60-
name = "RABBIT" or
61-
name = "BLOWFISH"
34+
name = ["AES", "AES128", "AES192", "AES256", "AES512", "RSA", "RABBIT", "BLOWFISH"]
6235
}
6336

6437
predicate isWeakEncryptionAlgorithm(string name) {
65-
name = "DES" or
66-
name = "3DES" or
67-
name = "TRIPLEDES" or
68-
name = "TDEA" or
69-
name = "TRIPLEDEA" or
70-
name = "ARC2" or
71-
name = "RC2" or
72-
name = "ARC4" or
73-
name = "RC4" or
74-
name = "ARCFOUR" or
75-
name = "ARC5" or
76-
name = "RC5"
38+
name =
39+
[
40+
"DES", "3DES", "TRIPLEDES", "TDEA", "TRIPLEDEA", "ARC2", "RC2", "ARC4", "RC4", "ARCFOUR",
41+
"ARC5", "RC5"
42+
]
7743
}
7844

7945
predicate isStrongPasswordHashingAlgorithm(string name) {
80-
name = "ARGON2" or
81-
name = "PBKDF2" or
82-
name = "BCRYPT" or
83-
name = "SCRYPT"
46+
name = ["ARGON2", "PBKDF2", "BCRYPT", "SCRYPT"]
8447
}
8548

8649
predicate isWeakPasswordHashingAlgorithm(string name) { none() }

python/ql/lib/semmle/python/objects/TObject.qll

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private predicate concrete_class(PythonClassObjectInternal cls) {
387387
not exists(Raise r, Name ex |
388388
r.getScope() = f and
389389
(r.getException() = ex or r.getException().(Call).getFunc() = ex) and
390-
(ex.getId() = "NotImplementedError" or ex.getId() = "NotImplemented")
390+
ex.getId() = ["NotImplementedError", "NotImplemented"]
391391
)
392392
)
393393
)
@@ -437,11 +437,7 @@ predicate missing_imported_module(ControlFlowNode imp, Context ctx, string name)
437437
* Helper for missing modules to determine if name `x.y` is a module `x.y` or
438438
* an attribute `y` of module `x`. This list should be added to as required.
439439
*/
440-
predicate common_module_name(string name) {
441-
name = "zope.interface"
442-
or
443-
name = "six.moves"
444-
}
440+
predicate common_module_name(string name) { name = ["zope.interface", "six.moves"] }
445441

446442
/**
447443
* A declaration of a class, either a built-in class or a source definition
@@ -482,16 +478,11 @@ library class ClassDecl extends @py_object {
482478
*/
483479
predicate isSpecial() {
484480
exists(string name | this = Builtin::special(name) |
485-
name = "type" or
486-
name = "super" or
487-
name = "bool" or
488-
name = "NoneType" or
489-
name = "tuple" or
490-
name = "property" or
491-
name = "ClassMethod" or
492-
name = "StaticMethod" or
493-
name = "MethodType" or
494-
name = "ModuleType"
481+
name =
482+
[
483+
"type", "super", "bool", "NoneType", "tuple", "property", "ClassMethod", "StaticMethod",
484+
"MethodType", "ModuleType"
485+
]
495486
)
496487
}
497488

@@ -514,11 +505,7 @@ library class ClassDecl extends @py_object {
514505

515506
/** Holds if this class is the abstract base class */
516507
predicate isAbstractBaseClass(string name) {
517-
exists(Module m |
518-
m.getName() = "_abcoll"
519-
or
520-
m.getName() = "_collections_abc"
521-
|
508+
exists(Module m | m.getName() = ["_abcoll", "_collections_abc"] |
522509
this.getClass().getScope() = m and
523510
this.getName() = name
524511
)

python/ql/lib/semmle/python/security/ClearText.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ module ClearTextLogging {
4747
meth.getObject(name).(NameNode).getId().matches("logg%") and
4848
call.getAnArg() = this
4949
|
50-
name = "error" or
51-
name = "warn" or
52-
name = "warning" or
53-
name = "debug" or
54-
name = "info"
50+
name = ["error", "warn", "warning", "debug", "info"]
5551
)
5652
}
5753
}

python/ql/lib/semmle/python/security/injection/Command.qll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ import semmle.python.security.strings.Untrusted
1414
abstract class CommandSink extends TaintSink { }
1515

1616
private ModuleObject osOrPopenModule() {
17-
result.getName() = "os" or
18-
result.getName() = "popen2"
17+
result.getName() = ["os", "popen2"]
1918
}
2019

2120
private Object makeOsCall() {
2221
exists(string name | result = ModuleObject::named("subprocess").attr(name) |
23-
name = "Popen" or
24-
name = "call" or
25-
name = "check_call" or
26-
name = "check_output" or
27-
name = "run"
22+
name = ["Popen", "call", "check_call", "check_output", "run"]
2823
)
2924
}
3025

@@ -65,8 +60,7 @@ class ShellCommand extends CommandSink {
6560
call.getAnArg() = this and
6661
call.getFunction().refersTo(osOrPopenModule().attr(name))
6762
|
68-
name = "system" or
69-
name = "popen" or
63+
name = ["system", "popen"] or
7064
name.matches("popen_")
7165
)
7266
or

0 commit comments

Comments
 (0)