2 * Mart Lubbers (s4109503)
6 #undef __analysis_assume
7 #include <CodeAnalysis\SourceAnnotations.h>
14 char *my_alloc(size_t size
)
17 char *ch
= (char *)calloc(size
, 1);
25 bool input([SA_Post(Tainted
=SA_Yes
)] _Out_cap_c_(BUF_SIZE
) char *buf
)
28 return (gets_s(buf
, BUF_SIZE
) != NULL
) ? true : false;
31 [returnvalue
:SA_Post(Tainted
=SA_Yes
)] char *do_read()
34 char *buf
= my_alloc(STR_SIZE
);
35 printf("Allocated a string at %p", buf
);
41 printf("empty string");
45 void copy_data([SA_Pre(Tainted
=SA_Yes
)]_In_count_c_(STR_SIZE
) char *buf1
, [SA_Post(Tainted
=SA_Yes
)] _Out_cap_c_(STR_SIZE
) char *buf2
)
47 memcpy(buf2
,buf1
,STR_SIZE
);
48 buf2
[STR_SIZE
-1] = NULL
; // null terminate, just in case
51 int execute([SA_Pre(Tainted
=SA_No
)] _In_count_c_(BUF_SIZE
) char *buf
)
53 return system(buf
); // pass buf as command to be executed by the OS
56 void validate([SA_Pre(Tainted
=SA_Yes
)][SA_Post(Tainted
=SA_No
)] _Inout_count_c_(BUF_SIZE
) char *buf
)
58 // This is a magical validation method, which turns tainted data
59 // into untainted data, for which the code not shown.
61 // A real implementation might for example use a whitelist to filter
65 _Check_return_
int test_ready()
71 int APIENTRY
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPSTR lpCmdLine
, int nCmdShow
)
73 char *buf1
= do_read();
74 char *buf2
= my_alloc(BUF_SIZE
);
77 if(test_ready() != 0){
78 printf("Test not ready\n");
85 char* buf3
= do_read();
86 copy_data(buf3
, buf2
);
91 char *buf4
= do_read();
97 // *****************************************************************
99 void zero(_Out_cap_(len
) int *buf
, int len
)
103 for(i
= 0; i
< len
; i
++)
108 _Out_cap_(len
) int *buf
, int len
,
109 _Out_cap_(len3
) int *buf3
, int len3
)
117 void zeroboth2(_Out_cap_(len3
) int *buf
, int len
, _Out_cap_(len
) int *buf3
, int len3
)
119 zeroboth(buf
, len3
, buf3
, len
);
127 zeroboth2(elements
, 100, oelements
, 200);