File tree Expand file tree Collapse file tree
ql/lib/semmle/code/cpp/commons Expand file tree Collapse file tree 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 =
1313 TTypeBoundsAnalysis ( ) or
1414 TValueFlowAnalysis ( )
1515
16+ /**
17+ * A reason for a specific buffer write size estimate
18+ */
1619class 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+ */
3748BufferWriteEstimationReason 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+ */
3960BufferWriteEstimationReason valueFlowAnalysis ( ) { result = TValueFlowAnalysis ( ) }
4061
4162class PrintfFormatAttribute extends FormatAttribute {
You can’t perform that action at this time.
0 commit comments