Skip to content

Commit d3d737b

Browse files
authored
Merge pull request #20330 from michaelnebel/python/ql4ql
Python: Fix some Ql4Ql violations.
2 parents 9d521e9 + 90caded commit d3d737b

File tree

10 files changed

+35
-43
lines changed

10 files changed

+35
-43
lines changed

python/ql/lib/analysis/DefinitionTracking.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private predicate ssa_phi_defn(PhiFunction phi, Definition defn) {
8383
ssa_variable_defn(phi.getAnInput(), defn)
8484
}
8585

86-
/** Holds if the ESSA defn `def` refers to (`value`, `cls`, `origin`) given the context `context`. */
86+
/** Holds if the ESSA defn `def` refers to (`value`, `cls`, `origin`) given the context `context`. */
8787
private predicate ssa_defn_defn(EssaDefinition def, Definition defn) {
8888
ssa_phi_defn(def, defn)
8989
or

python/ql/lib/experimental/cryptography/CryptoArtifact.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ abstract class CryptographicAlgorithm extends CryptographicArtifact {
9595
/**
9696
* Normalizes a raw name into a normalized name as found in `CryptoAlgorithmNames.qll`.
9797
* Subclassess should override for more api-specific normalization.
98-
* By deafult, converts a raw name to upper-case with no hyphen, underscore, hash, or space.
98+
* By default, converts a raw name to upper-case with no hyphen, underscore, hash, or space.
9999
*/
100100
bindingset[s]
101101
string normalizeName(string s) {

python/ql/lib/experimental/cryptography/modules/CryptographyModule.qll

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,25 @@ module KDF {
117117
override predicate requiresIteration() { this.getAlgorithm().getKDFName() in ["PBKDF2HMAC"] }
118118

119119
override DataFlow::Node getIterationSizeSrc() {
120-
if this.requiresIteration()
121-
then
122-
// ASSUMPTION: ONLY EVER in arg 3 in PBKDF2HMAC
123-
result = Utils::getUltimateSrcFromApiNode(this.getParameter(3, "iterations"))
124-
else none()
120+
this.requiresIteration() and
121+
// ASSUMPTION: ONLY EVER in arg 3 in PBKDF2HMAC
122+
result = Utils::getUltimateSrcFromApiNode(this.getParameter(3, "iterations"))
125123
}
126124

127125
override DataFlow::Node getSaltConfigSrc() {
128-
if this.requiresSalt()
129-
then
130-
// SCRYPT has it in arg 1
131-
if this.getAlgorithm().getKDFName() = "SCRYPT"
132-
then result = Utils::getUltimateSrcFromApiNode(this.getParameter(1, "salt"))
133-
else
134-
// EVERYTHING ELSE that uses salt is in arg 2
135-
result = Utils::getUltimateSrcFromApiNode(this.getParameter(2, "salt"))
136-
else none()
126+
this.requiresSalt() and
127+
// SCRYPT has it in arg 1
128+
if this.getAlgorithm().getKDFName() = "SCRYPT"
129+
then result = Utils::getUltimateSrcFromApiNode(this.getParameter(1, "salt"))
130+
else
131+
// EVERYTHING ELSE that uses salt is in arg 2
132+
result = Utils::getUltimateSrcFromApiNode(this.getParameter(2, "salt"))
137133
}
138134

139135
override DataFlow::Node getHashConfigSrc() {
140-
if this.requiresHash()
141-
then
142-
// ASSUMPTION: ONLY EVER in arg 0
143-
result = Utils::getUltimateSrcFromApiNode(this.getParameter(0, "algorithm"))
144-
else none()
136+
this.requiresHash() and
137+
// ASSUMPTION: ONLY EVER in arg 0
138+
result = Utils::getUltimateSrcFromApiNode(this.getParameter(0, "algorithm"))
145139
}
146140

147141
// TODO: get encryption algorithm for CBC-based KDF?
@@ -152,11 +146,9 @@ module KDF {
152146
}
153147

154148
override DataFlow::Node getModeSrc() {
155-
if this.requiresMode()
156-
then
157-
// ASSUMPTION: ONLY EVER in arg 1
158-
result = Utils::getUltimateSrcFromApiNode(this.getParameter(1, "mode"))
159-
else none()
149+
this.requiresMode() and
150+
// ASSUMPTION: ONLY EVER in arg 1
151+
result = Utils::getUltimateSrcFromApiNode(this.getParameter(1, "mode"))
160152
}
161153
}
162154
}

python/ql/lib/experimental/cryptography/modules/stdlib/HashlibModule.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ module KDF {
201201

202202
// TODO: better modeling of scrypt
203203
/**
204-
* Identifies key derivation fucntion hashlib.scrypt accesses.
204+
* Identifies key derivation function hashlib.scrypt accesses.
205205
*/
206206
class HashlibScryptAlgorithm extends KeyDerivationAlgorithm, KeyDerivationOperation {
207207
HashlibScryptAlgorithm() { this = API::moduleImport("hashlib").getMember("scrypt").getACall() }

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ DataFlowType getNodeType(Node node) {
613613
// Extra flow
614614
//--------
615615
/**
616-
* Holds if `pred` can flow to `succ`, by jumping from one callable to
616+
* Holds if `nodeFrom` can flow to `nodeTo`, by jumping from one callable to
617617
* another. Additional steps specified by the configuration are *not*
618618
* taken into account.
619619
*/
@@ -634,7 +634,7 @@ predicate jumpStep(Node nodeFrom, Node nodeTo) {
634634
* the type-trackers as well, as that would make evaluation of type-tracking recursive
635635
* with the new jumpsteps.
636636
*
637-
* Holds if `pred` can flow to `succ`, by jumping from one callable to
637+
* Holds if `nodeFrom` can flow to `nodeTo`, by jumping from one callable to
638638
* another. Additional steps specified by the configuration are *not*
639639
* taken into account.
640640
*/
@@ -657,7 +657,7 @@ predicate jumpStepSharedWithTypeTracker(Node nodeFrom, Node nodeTo) {
657657
* the type-trackers as well, as that would make evaluation of type-tracking recursive
658658
* with the new jumpsteps.
659659
*
660-
* Holds if `pred` can flow to `succ`, by jumping from one callable to
660+
* Holds if `nodeFrom` can flow to `nodeTo`, by jumping from one callable to
661661
* another. Additional steps specified by the configuration are *not*
662662
* taken into account.
663663
*/
@@ -766,7 +766,7 @@ module Orm {
766766
abstract predicate storeStep(Node nodeFrom, Content c, Node nodeTo);
767767

768768
/**
769-
* Holds if `pred` can flow to `succ`, by jumping from one callable to
769+
* Holds if `nodeFrom` can flow to `nodeTo`, by jumping from one callable to
770770
* another. Additional steps specified by the configuration are *not*
771771
* taken into account.
772772
*/

python/ql/lib/semmle/python/frameworks/Stdlib.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,11 +3702,8 @@ module StdlibPrivate {
37023702
* A call to a find method on a tree or an element will execute an XPath expression.
37033703
*/
37043704
private class ElementTreeFindCall extends XML::XPathExecution::Range, DataFlow::CallCfgNode {
3705-
string methodName;
3706-
37073705
ElementTreeFindCall() {
3708-
methodName in ["find", "findall", "findtext"] and
3709-
(
3706+
exists(string methodName | methodName in ["find", "findall", "findtext"] |
37103707
this = elementTreeInstance().getMember(methodName).getACall()
37113708
or
37123709
this = elementInstance().getMember(methodName).getACall()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ class ObjectInternal extends TObject {
174174
abstract int length();
175175

176176
/**
177-
* Holds if the object `function` is called when this object is called and `paramOffset`
177+
* Holds if the object `function` is called when this object is called and `offset`
178178
* is the difference from the parameter position and the argument position.
179-
* For a normal function `paramOffset` is 0. For classes and bound-methods it is 1.
179+
* For a normal function `offset` is 0. For classes and bound-methods it is 1.
180180
* This is used to implement the `CallableValue` public API.
181181
*/
182182
predicate functionAndOffset(CallableObjectInternal function, int offset) { none() }

python/ql/lib/semmle/python/types/FunctionObject.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ abstract class FunctionObject extends Object {
4646
ControlFlowNode getACall() { result = this.theCallable().getACall() }
4747

4848
/** Gets a call-site from where this function is called, given the `context` */
49-
ControlFlowNode getACall(Context caller_context) {
50-
result = this.theCallable().getACall(caller_context)
51-
}
49+
ControlFlowNode getACall(Context context) { result = this.theCallable().getACall(context) }
5250

5351
/**
5452
* Gets the `ControlFlowNode` that will be passed as the nth argument to `this` when called at `call`.

python/ql/src/Security/CWE-327/FluentApiModel.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TlsLibraryModel
1515
* The state is represented as a bit vector, where each bit corresponds to a
1616
* protocol version. The bit is set if the protocol is allowed.
1717
*/
18-
module InsecureContextConfiguration implements DataFlow::StateConfigSig {
18+
module InsecureContextConfig implements DataFlow::StateConfigSig {
1919
private newtype TFlowState =
2020
TMkFlowState(TlsLibrary library, int bits) {
2121
bits in [0 .. max(any(ProtocolVersion v).getBit()) * 2 - 1]
@@ -116,7 +116,12 @@ module InsecureContextConfiguration implements DataFlow::StateConfigSig {
116116
}
117117
}
118118

119-
private module InsecureContextFlow = DataFlow::GlobalWithState<InsecureContextConfiguration>;
119+
/**
120+
* DEPRECATED: Renamed to `InsecureContextConfig`.
121+
*/
122+
deprecated module InsecureContextConfiguration = InsecureContextConfig;
123+
124+
private module InsecureContextFlow = DataFlow::GlobalWithState<InsecureContextConfig>;
120125

121126
/**
122127
* Holds if `conectionCreation` marks the creation of a connection based on the contex

python/ql/src/experimental/Security/CWE-022bis/TarSlipImprov.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private module TarSlipImprovConfig implements DataFlow::ConfigSig {
6363
// For a call to `file.extractall` without `members` argument, `file` is considered a sink.
6464
exists(MethodCallNode call, AllTarfileOpens atfo |
6565
call = atfo.getReturn().getMember("extractall").getACall() and
66-
not exists(Node arg | arg = call.getArgByName("members")) and
66+
not exists(call.getArgByName("members")) and
6767
sink = call.getObject()
6868
)
6969
or

0 commit comments

Comments
 (0)