File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
ql/lib/semmle/code/cpp/commons Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ lgtm,codescanning
2
+ * new predicates extend ` BufferWrite::getMaxData ` and ` FormatLiteral::etMaxConvertedLength ` (and their ` Limited ` variants)
3
+ with an estimation reason, that can be ` typeBoundsAnalysis() ` or ` valueFlowAnalysis() `
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ private newtype TBufferWriteEstimationReason =
13
13
TTypeBoundsAnalysis ( ) or
14
14
TValueFlowAnalysis ( )
15
15
16
+ /**
17
+ * A reason for a specific buffer write size estimate
18
+ */
16
19
class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
17
20
BufferWriteEstimationReason ( ) {
18
21
this = TTypeBoundsAnalysis ( ) or
@@ -25,6 +28,10 @@ class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
25
28
this = TValueFlowAnalysis ( ) and result = "based on flow analysis of value bounds"
26
29
}
27
30
31
+ /**
32
+ * Combine estimate reasons. Used to give a reason for the size of a format string
33
+ * conversion given reasons coming from its individual specifiers
34
+ */
28
35
BufferWriteEstimationReason combineWith ( BufferWriteEstimationReason other ) {
29
36
( this = TTypeBoundsAnalysis ( ) or other = TTypeBoundsAnalysis ( ) ) and
30
37
result = TTypeBoundsAnalysis ( )
@@ -34,8 +41,22 @@ class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
34
41
}
35
42
}
36
43
44
+ /**
45
+ * The estimation comes from rough bounds just based on the type (e.g.
46
+ * `0 <= x < 2^32` for an unsigned 32 bit integer)
47
+ */
37
48
BufferWriteEstimationReason typeBoundsAnalysis ( ) { result = TTypeBoundsAnalysis ( ) }
38
49
50
+ /**
51
+ * The estimation comes from non trivial bounds found via actual flow analysis.
52
+ * For example
53
+ * ```
54
+ * unsigned u = x;
55
+ * if (u < 1000) {
56
+ * //... <- estimation done here based on u
57
+ * }
58
+ * ```
59
+ */
39
60
BufferWriteEstimationReason valueFlowAnalysis ( ) { result = TValueFlowAnalysis ( ) }
40
61
41
62
class PrintfFormatAttribute extends FormatAttribute {
You can’t perform that action at this time.
0 commit comments