@@ -182,7 +182,7 @@ private class MaxValueState extends TMaxValueState {
182
182
}
183
183
184
184
/**
185
- * Gets whether what bitsize we should use for a sink.
185
+ * Gets the bitsize we should use for a sink.
186
186
*
187
187
* If the architecture bit size is known, then we should use that. Otherwise,
188
188
* we should use 32 bits, because that will lead to more results.
@@ -191,6 +191,7 @@ private class MaxValueState extends TMaxValueState {
191
191
if this = TMkMaxValueState ( _, TMk64Bit ( ) ) then result = 64 else result = 32
192
192
}
193
193
194
+ /** Gets a textual representation of this element. */
194
195
string toString ( ) {
195
196
exists ( string suffix |
196
197
if exists ( this .getArchitectureBitSize ( ) )
@@ -226,6 +227,13 @@ abstract class BarrierFlowStateTransformer extends DataFlow::Node {
226
227
abstract MaxValueState transform ( MaxValueState flowstate ) ;
227
228
}
228
229
230
+ /**
231
+ * A node that is safely guarded by an `UpperBoundCheckGuard`.
232
+ *
233
+ * When this guarantees that a variable in the non-constant operand is less
234
+ * than some value this may be a barrier guard which should block some flow
235
+ * states and transform some others as they flow through.
236
+ */
229
237
class UpperBoundCheck extends BarrierFlowStateTransformer {
230
238
UpperBoundCheckGuard g ;
231
239
@@ -253,6 +261,13 @@ class UpperBoundCheck extends BarrierFlowStateTransformer {
253
261
}
254
262
}
255
263
264
+ /**
265
+ * Holds if `source` is the result of a call to `strconv.Atoi`,
266
+ * `strconv.ParseInt`, or `strconv.ParseUint`, `bitSize` is the bit size of
267
+ * the smallest integer type which the result could be converted to without
268
+ * data loss, and `isSigned` is true if the result is parsed as a signed
269
+ * integer.
270
+ */
256
271
predicate isSourceWithBitSize ( DataFlow:: Node source , int bitSize , boolean isSigned ) {
257
272
exists ( DataFlow:: CallNode c , IntegerParser:: Range ip , int apparentBitSize |
258
273
c = ip .getACall ( ) and
@@ -342,19 +357,20 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
342
357
}
343
358
344
359
predicate isBarrier ( DataFlow:: Node node , FlowState state ) {
345
- // when the flowstate is transformed at a call node, block the original
346
- // flowstate value.
360
+ // Safely guarded by a barrier guard.
347
361
exists ( BarrierFlowStateTransformer bfst | node = bfst and bfst .barrierFor ( state ) |
348
362
not exists ( bfst .transform ( state ) ) or bfst .transform ( state ) != state
349
363
)
350
364
or
365
+ // When there is a flow from a source to a sink, do not allow the flow to
366
+ // continue to a further sink.
351
367
isSink2 ( node , state )
352
368
}
353
369
354
370
predicate isAdditionalFlowStep (
355
371
DataFlow:: Node node1 , FlowState state1 , DataFlow:: Node node2 , FlowState state2
356
372
) {
357
- // create additional flow steps for `BarrierFlowStateTransformer`s
373
+ // Create additional flow steps for `BarrierFlowStateTransformer`s
358
374
state2 = node2 .( BarrierFlowStateTransformer ) .transform ( state1 ) and
359
375
DataFlow:: simpleLocalFlowStep ( node1 , node2 )
360
376
}
0 commit comments