@@ -182,7 +182,7 @@ private class MaxValueState extends TMaxValueState {
182182 }
183183
184184 /**
185- * Gets whether what bitsize we should use for a sink.
185+ * Gets the bitsize we should use for a sink.
186186 *
187187 * If the architecture bit size is known, then we should use that. Otherwise,
188188 * we should use 32 bits, because that will lead to more results.
@@ -191,6 +191,7 @@ private class MaxValueState extends TMaxValueState {
191191 if this = TMkMaxValueState ( _, TMk64Bit ( ) ) then result = 64 else result = 32
192192 }
193193
194+ /** Gets a textual representation of this element. */
194195 string toString ( ) {
195196 exists ( string suffix |
196197 if exists ( this .getArchitectureBitSize ( ) )
@@ -226,6 +227,13 @@ abstract class BarrierFlowStateTransformer extends DataFlow::Node {
226227 abstract MaxValueState transform ( MaxValueState flowstate ) ;
227228}
228229
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+ */
229237class UpperBoundCheck extends BarrierFlowStateTransformer {
230238 UpperBoundCheckGuard g ;
231239
@@ -253,6 +261,13 @@ class UpperBoundCheck extends BarrierFlowStateTransformer {
253261 }
254262}
255263
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+ */
256271predicate isSourceWithBitSize ( DataFlow:: Node source , int bitSize , boolean isSigned ) {
257272 exists ( DataFlow:: CallNode c , IntegerParser:: Range ip , int apparentBitSize |
258273 c = ip .getACall ( ) and
@@ -342,19 +357,20 @@ private module ConversionWithoutBoundsCheckConfig implements DataFlow::StateConf
342357 }
343358
344359 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.
347361 exists ( BarrierFlowStateTransformer bfst | node = bfst and bfst .barrierFor ( state ) |
348362 not exists ( bfst .transform ( state ) ) or bfst .transform ( state ) != state
349363 )
350364 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.
351367 isSink2 ( node , state )
352368 }
353369
354370 predicate isAdditionalFlowStep (
355371 DataFlow:: Node node1 , FlowState state1 , DataFlow:: Node node2 , FlowState state2
356372 ) {
357- // create additional flow steps for `BarrierFlowStateTransformer`s
373+ // Create additional flow steps for `BarrierFlowStateTransformer`s
358374 state2 = node2 .( BarrierFlowStateTransformer ) .transform ( state1 ) and
359375 DataFlow:: simpleLocalFlowStep ( node1 , node2 )
360376 }
0 commit comments