File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
c/cert/test/rules/CON34-C Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <threads.h>
4
+
5
+ static tss_t k ;
6
+
7
+ void t1 (void * v ) {
8
+ int * value = (int * )v ;
9
+ int a = * value + 1 ;
10
+ }
11
+
12
+ void t2 (void * v ) {
13
+ int * value =
14
+ tss_get (k ); // NON_COMPLIANT (AUDIT) - A threaded function without a
15
+ // `tss_set` should be considered suspicious.
16
+ int a = * value + 1 ;
17
+ }
18
+
19
+ void m1 () {
20
+ thrd_t id ;
21
+ int value ;
22
+
23
+ thrd_create (& id , t1 , & value ); // NON_COMPLIANT
24
+ }
25
+
26
+ void m2 () {
27
+ thrd_t id ;
28
+ int * value = (int * )malloc (sizeof (int ));
29
+
30
+ thrd_create (& id , t1 , value ); // COMPLIANT - free is never called
31
+ }
32
+
33
+ void m3 () {
34
+ thrd_t id ;
35
+ int * value = (int * )malloc (sizeof (int ));
36
+
37
+ thrd_create (& id , t1 ,
38
+ value ); // COMPLIANT - free is called without synchronization,
39
+ // however this is beyond the scope of this query.
40
+ free (value );
41
+ }
42
+
43
+ void m4 () {
44
+ thrd_t id ;
45
+ int * value = (int * )malloc (sizeof (int ));
46
+
47
+ thrd_create (& id , t1 , value ); // COMPLIANT
48
+
49
+ thrd_join (id , NULL );
50
+
51
+ free (value );
52
+ }
53
+
54
+ void m5 () {
55
+ thrd_t id ;
56
+ int * value = (int * )malloc (sizeof (int ));
57
+
58
+ tss_set (k , value );
59
+
60
+ void * p = tss_get (k );
61
+
62
+ thrd_create (& id , t1 , p ); // COMPLIANT
63
+ }
64
+
65
+ void m6 (void * v ) {
66
+ int * value =
67
+ tss_get (k ); // COMPLIANT (AUDIT) - A non-threaded function without a
68
+ // `tss_set` should not be considered suspicious.
69
+ int a = * value + 1 ;
70
+ }
71
+
72
+ void m7 () {
73
+ thrd_t id ;
74
+ int * value = (int * )malloc (sizeof (int ));
75
+ thrd_create (& id , t2 ,
76
+ value ); // COMPLIANT - note that t2 (which is now a threaded
77
+ // function) is NON_COMPLIANT in an audit query.
78
+ }
You can’t perform that action at this time.
0 commit comments