Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 9c7e463

Browse files
author
Max Schaefer
committed
Simplify logic in AllocationSizeOverflow query.
1 parent 9b53ad3 commit 9c7e463

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

ql/src/semmle/go/security/AllocationSizeOverflowCustomizations.qll

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ module AllocationSizeOverflow {
5151
exists(MarshalingFunction marshal, DataFlow::CallNode call |
5252
call = marshal.getACall() and
5353
// rule out cases where we can tell that the result will always be small
54-
not forall(FunctionInput inp | inp = marshal.getAnInput() |
55-
isSmall(inp.getNode(call).asExpr())
54+
exists(FunctionInput inp | inp = marshal.getAnInput() |
55+
isBig(inp.getNode(call).asExpr())
5656
) and
5757
this = marshal.getOutput().getNode(call)
5858
)
@@ -152,26 +152,17 @@ module AllocationSizeOverflow {
152152
exists(StructType st | st = t | forall(Field f | f = st.getField(_) | isSmallType(f.getType())))
153153
}
154154

155-
/** Holds if `e` is an expression whose values are likely to marshal to relatively small blobs. */
156-
private predicate isSmall(Expr e) {
157-
isSmallType(e.getType())
158-
or
159-
e.isConst()
155+
/** Holds if `e` is an expression whose values might marshal to relatively large blobs. */
156+
private predicate isBig(Expr e) {
157+
not isSmallType(e.getType()) and
158+
not e.isConst()
160159
or
161160
exists(KeyValueExpr kv | kv = e |
162-
isSmall(kv.getKey()) and
163-
isSmall(kv.getValue())
161+
isBig(kv.getKey()) or
162+
isBig(kv.getValue())
164163
)
165164
or
166-
isSmallCompositeLit(e, 0)
167-
}
168-
169-
/** Holds if elements `n` and above of `lit` are small. */
170-
private predicate isSmallCompositeLit(CompositeLit lit, int n) {
171-
n = lit.getNumElement()
172-
or
173-
isSmall(lit.getElement(n)) and
174-
isSmallCompositeLit(lit, n + 1)
165+
isBig(e.(CompositeLit).getAnElement())
175166
}
176167

177168
/**

0 commit comments

Comments
 (0)