File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed
Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,11 @@ class ArrayAllocation extends TArrayAllocation {
105105 result = this .asStackAllocation ( ) .getLocation ( ) or
106106 result = this .asDynamicAllocation ( ) .getLocation ( )
107107 }
108+
109+ DataFlow:: Node getNode ( ) {
110+ result .asExpr ( ) = this .asStackAllocation ( ) .getInitExpr ( ) or
111+ result .asConvertedExpr ( ) = this .asDynamicAllocation ( )
112+ }
108113}
109114
110115class PointerFormation extends TPointerFormation {
@@ -147,21 +152,16 @@ class PointerFormation extends TPointerFormation {
147152
148153module TrackArrayConfig implements DataFlow:: ConfigSig {
149154 predicate isSource ( DataFlow:: Node node ) {
150- /* 1. Declaring / Initializing an array-type variable */
151- exists ( ArrayAllocation arrayAllocation |
152- node .asExpr ( ) = arrayAllocation .asStackAllocation ( ) .getInitExpr ( )
153- )
154- or
155- /* 2. Allocating dynamic memory as an array */
156- none ( ) // TODO
155+ exists ( ArrayAllocation arrayAllocation | node = arrayAllocation .getNode ( ) )
157156 }
158157
159158 predicate isSink ( DataFlow:: Node node ) {
160159 exists ( PointerFormation pointerFormation | node = pointerFormation .getNode ( ) )
161160 }
162161}
163162
164- module TrackArray = DataFlow:: Global< TrackArrayConfig > ;
163+ import semmle.code.cpp.dataflow.new.TaintTracking
164+ module TrackArray = TaintTracking:: Global< TrackArrayConfig > ;
165165
166166private predicate arrayDeclarationAndAccess (
167167 DataFlow:: Node arrayDeclarationNode , DataFlow:: Node pointerFormationNode
Original file line number Diff line number Diff line change @@ -72,11 +72,11 @@ int main(int argc, char *argv[]) {
7272 num_of_elements_realloc = 6 ;
7373 }
7474
75- int *array_malloc = (int *)std:: malloc (num_of_elements_malloc * sizeof (int ));
76- int *array_calloc = (int *)std:: calloc (num_of_elements_calloc, sizeof (int ));
75+ int *array_malloc = (int *)malloc (num_of_elements_malloc * sizeof (int ));
76+ int *array_calloc = (int *)calloc (num_of_elements_calloc, sizeof (int ));
7777
7878 int *array_realloc =
79- (int *)std:: realloc (array_malloc, num_of_elements_realloc * sizeof (int ));
79+ (int *)realloc (array_malloc, num_of_elements_realloc * sizeof (int ));
8080
8181 f1 (array_malloc);
8282 f2 (array_malloc);
You can’t perform that action at this time.
0 commit comments