Skip to content

Commit a6cbe6f

Browse files
authored
C++: add missing change note and docs
1 parent fb03561 commit a6cbe6f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
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()`

cpp/ql/lib/semmle/code/cpp/commons/Printf.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ private newtype TBufferWriteEstimationReason =
1313
TTypeBoundsAnalysis() or
1414
TValueFlowAnalysis()
1515

16+
/**
17+
* A reason for a specific buffer write size estimate
18+
*/
1619
class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
1720
BufferWriteEstimationReason() {
1821
this = TTypeBoundsAnalysis() or
@@ -25,6 +28,10 @@ class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
2528
this = TValueFlowAnalysis() and result = "based on flow analysis of value bounds"
2629
}
2730

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+
*/
2835
BufferWriteEstimationReason combineWith(BufferWriteEstimationReason other) {
2936
(this = TTypeBoundsAnalysis() or other = TTypeBoundsAnalysis()) and
3037
result = TTypeBoundsAnalysis()
@@ -34,8 +41,22 @@ class BufferWriteEstimationReason extends TBufferWriteEstimationReason {
3441
}
3542
}
3643

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+
*/
3748
BufferWriteEstimationReason typeBoundsAnalysis() { result = TTypeBoundsAnalysis() }
3849

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+
*/
3960
BufferWriteEstimationReason valueFlowAnalysis() { result = TValueFlowAnalysis() }
4061

4162
class PrintfFormatAttribute extends FormatAttribute {

0 commit comments

Comments
 (0)