Skip to content

Commit 40cbfc7

Browse files
committed
work
1 parent 9243c93 commit 40cbfc7

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
No expected results have yet been specified
1+
| main.c:23:3:23:13 | call to thrd_create | $@ not declared with appropriate storage duration | main.c:23:24:23:29 | & ... | Shared object |
2+
| main.c:74:3:74:13 | call to thrd_create | $@ not declared with appropriate storage duration | main.c:74:24:74:24 | p | Shared object |
3+
| main.c:85:3:85:13 | call to thrd_create | $@ not declared with appropriate storage duration | main.c:85:24:85:24 | p | Shared object |
4+
| main.c:94:3:94:13 | call to thrd_create | $@ not declared with appropriate storage duration | main.c:94:24:94:24 | p | Shared object |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| main.c:14:7:14:13 | call to tss_get | Call to a thread specific storage function from within a threaded context on an object that may not be owned by this thread. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/CON34-C/ThreadObjectStorageDurationsNotInitialized.ql

c/cert/test/rules/CON34-C/main.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,62 @@ void m5() {
5555
thrd_t id;
5656
int *value = (int *)malloc(sizeof(int));
5757

58+
tss_create(&k, free);
5859
tss_set(k, value);
5960

6061
void *p = tss_get(k);
6162

6263
thrd_create(&id, t1, p); // COMPLIANT
6364
}
6465

65-
void m6(void *v) {
66+
void m5a() {
67+
thrd_t id;
68+
int *value = (int *)malloc(sizeof(int));
69+
70+
tss_set(k, value);
71+
72+
void *p = tss_get(k);
73+
74+
thrd_create(&id, t1, p); // NON_COMPLIANT - k not initialized.
75+
}
76+
77+
void m6() {
78+
thrd_t id;
79+
int *value = (int *)malloc(sizeof(int));
80+
81+
tss_create(&k, free);
82+
83+
void *p = tss_get(k);
84+
85+
thrd_create(&id, t1, p); // NON_COMPLIANT -- get without set
86+
}
87+
88+
void m6a() {
89+
thrd_t id;
90+
int *value = (int *)malloc(sizeof(int));
91+
92+
void *p = tss_get(k);
93+
94+
thrd_create(&id, t1, p); // NON_COMPLIANT -- get without set
95+
}
96+
97+
void m7(void *v) {
6698
int *value =
6799
tss_get(k); // COMPLIANT (AUDIT) - A non-threaded function without a
68100
// `tss_set` should not be considered suspicious.
69101
int a = *value + 1;
70102
}
71103

72-
void m7() {
104+
void m8() {
73105
thrd_t id;
74106
int *value = (int *)malloc(sizeof(int));
75107
thrd_create(&id, t2,
76108
value); // COMPLIANT - note that t2 (which is now a threaded
77109
// function) is NON_COMPLIANT in an audit query.
78110
}
111+
112+
void m9() {
113+
thrd_t id;
114+
static int value = 100;
115+
thrd_create(&id, t1, &value); // COMPLIANT - compliant for static values.
116+
}

0 commit comments

Comments
 (0)