File tree Expand file tree Collapse file tree 8 files changed +153
-0
lines changed Expand file tree Collapse file tree 8 files changed +153
-0
lines changed Original file line number Diff line number Diff line change
1
+ default : tests.log
2
+
3
+ FLAGS = --verbosity 10
4
+
5
+ test :
6
+ @../test.pl -p -c " ../../../src/2ls/2ls $( FLAGS) "
7
+
8
+ tests.log : ../test.pl
9
+ @../test.pl -p -c " ../../../src/2ls/2ls $( FLAGS) "
10
+
11
+ show :
12
+ @for dir in * ; do \
13
+ if [ -d " $$ dir" ]; then \
14
+ vim -o " $$ dir/*.c" " $$ dir/*.out" ; \
15
+ fi ; \
16
+ done ;
17
+
18
+ clean :
19
+ @rm -f * .log
20
+ @for dir in * ; do rm -f $$ dir/* .out; done ;
Original file line number Diff line number Diff line change
1
+ // Inspired by SV-comp:
2
+ // https://sv-comp.sosy-lab.org/2023/results/sv-benchmarks/c/Juliet_Test/CWE190_Integer_Overflow__int64_t_fscanf_add_01_bad.i
3
+
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+ #include <time.h>
7
+
8
+ void printLine (const char * line );
9
+ void printLongLine (long longNumber );
10
+
11
+ void CWE190_Integer_Overflow__int64_t_fscanf_add_01_bad ()
12
+ {
13
+ int64_t data ;
14
+ data = 0LL ;
15
+ fscanf (stdin , "%" "l" "d" , & data );
16
+ {
17
+ int64_t result = data + 1 ;
18
+ printLongLongLine (result );
19
+ }
20
+ }
21
+ int main (int argc , char * argv [])
22
+ {
23
+ srand ( (unsigned )time (((void * )0 )) );
24
+ printLine ("Calling bad()..." );
25
+ CWE190_Integer_Overflow__int64_t_fscanf_add_01_bad ();
26
+ printLine ("Finished bad()" );
27
+ return 0 ;
28
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --signed-overflow-check
4
+ ^EXIT=10$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
Original file line number Diff line number Diff line change
1
+ // Inspired by SV-comp:
2
+ // https://sv-comp.sosy-lab.org/2023/results/sv-benchmarks/c/Juliet_Test/CWE190_Integer_Overflow__int64_t_fscanf_add_01_good.i
3
+
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+ #include <time.h>
7
+
8
+ void printLine (const char * line );
9
+ void printLongLine (long longNumber );
10
+ void printLongLongLine (int64_t longLongIntNumber );
11
+
12
+ static void goodG2B ()
13
+ {
14
+ int64_t data ;
15
+ data = 0LL ;
16
+ data = 2 ;
17
+ {
18
+ int64_t result = data + 1 ;
19
+ printLongLongLine (result );
20
+ }
21
+ }
22
+ static void goodB2G ()
23
+ {
24
+ int64_t data ;
25
+ data = 0LL ;
26
+ fscanf (stdin , "%" "l" "d" , & data );
27
+ if (data < 0x7fffffffffffffffLL )
28
+ {
29
+ int64_t result = data + 1 ;
30
+ printLongLongLine (result );
31
+ }
32
+ else
33
+ {
34
+ printLine ("data value is too large to perform arithmetic safely." );
35
+ }
36
+ }
37
+ void CWE190_Integer_Overflow__int64_t_fscanf_add_01_good ()
38
+ {
39
+ goodG2B ();
40
+ goodB2G ();
41
+ }
42
+ int main (int argc , char * argv [])
43
+ {
44
+ srand ( (unsigned )time (((void * )0 )) );
45
+ printLine ("Calling good()..." );
46
+ CWE190_Integer_Overflow__int64_t_fscanf_add_01_good ();
47
+ printLine ("Finished good()" );
48
+ return 0 ;
49
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --signed-overflow-check
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
Original file line number Diff line number Diff line change @@ -1048,6 +1048,8 @@ bool twols_parse_optionst::process_goto_program(
1048
1048
if (options.get_bool_option (" competition-mode" ))
1049
1049
assert_no_builtin_functions (goto_model);
1050
1050
1051
+ make_scanf_nondet (goto_model);
1052
+
1051
1053
#if REMOVE_MULTIPLE_DEREFERENCES
1052
1054
remove_multiple_dereferences (goto_model);
1053
1055
#endif
Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ class twols_parse_optionst:
190
190
void fix_goto_targets (goto_modelt &goto_model);
191
191
void make_assertions_false (goto_modelt &goto_model);
192
192
void make_symbolic_array_indices (goto_modelt &goto_model);
193
+ void make_scanf_nondet (goto_modelt &goto_model);
193
194
};
194
195
195
196
#endif
Original file line number Diff line number Diff line change @@ -849,3 +849,44 @@ void twols_parse_optionst::make_symbolic_array_indices(goto_modelt &goto_model)
849
849
}
850
850
goto_model.goto_functions .update ();
851
851
}
852
+
853
+ // / Makes user input nondeterministic, i.e. arguments of fscanf starting
854
+ // / from the second one are assigned a nondeterministic value.
855
+ void twols_parse_optionst::make_scanf_nondet (goto_modelt &goto_model)
856
+ {
857
+ for (auto &f_it : goto_model.goto_functions .function_map )
858
+ {
859
+ Forall_goto_program_instructions (i_it, f_it.second .body )
860
+ {
861
+ if (!i_it->is_function_call ())
862
+ continue ;
863
+ auto name = to_symbol_expr (i_it->call_function ()).get_identifier ();
864
+ // FIXME: this is a bit hacky and should probably be handled better in
865
+ // coordination with CBMC.
866
+ int start;
867
+ if (name == " __isoc99_fscanf" || name == " fscanf" )
868
+ start = 2 ;
869
+ else if (name == " __isoc99_scanf" || name == " scanf" )
870
+ start = 1 ;
871
+ else
872
+ continue ;
873
+ int i = 0 ;
874
+ for (const auto &arg : i_it->call_arguments ()) {
875
+ if (i >= start)
876
+ {
877
+ if (arg.id () == ID_address_of)
878
+ {
879
+ auto lhs=dereference_exprt (arg);
880
+ side_effect_expr_nondett rhs (
881
+ to_address_of_expr (arg).object ().type (),
882
+ i_it->source_location ());
883
+ f_it.second .body .insert_after (
884
+ i_it,
885
+ goto_programt::make_assignment (lhs, rhs));
886
+ }
887
+ }
888
+ i++;
889
+ }
890
+ }
891
+ }
892
+ }
You can’t perform that action at this time.
0 commit comments