Skip to content

Commit e444f7c

Browse files
authored
Merge pull request #13 from github/s-samadi/banned
Add the queries defined in the Banned package for the C language.
2 parents 76d1b9d + 2f6c80a commit e444f7c

File tree

107 files changed

+4038
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+4038
-13
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"type": "pickString",
164164
"options": [
165165
"Allocations",
166+
"Banned",
166167
"BannedFunctions",
167168
"BannedSyntax",
168169
"BannedTypes",

c/cert/src/rules/ENV33-C/DoNotCallSystem.md

Lines changed: 300 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @id c/cert/do-not-call-system
3+
* @name ENV33-C: Do not call 'system'
4+
* @description Use of the 'system' function may result in exploitable vulnerabilities.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/cert/id/env33-c
9+
* security
10+
* external/cert/obligtion/rule
11+
*/
12+
13+
import cpp
14+
import codingstandards.c.cert
15+
import semmle.code.cpp.security.CommandExecution
16+
17+
from FunctionCall call, SystemFunction target
18+
where
19+
not isExcluded(call, BannedPackage::doNotCallSystemQuery()) and
20+
call.getTarget() = target and
21+
// Exclude calls to `system` with a `NULL` pointer, because it is allowed to determine the presence of a command processor.
22+
(target.getName() = "system" implies not call.getAnArgument().(Literal).getValue() = "0")
23+
select call, "Call to banned function $@.", target, target.getName()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.c:10:3:10:8 | call to system | Call to banned function $@. | test.c:4:5:4:10 | system | system |
2+
| test.c:12:8:12:12 | call to popen | Call to banned function $@. | test.c:6:7:6:11 | popen | popen |
3+
| test.c:20:3:20:8 | call to system | Call to banned function $@. | test.c:4:5:4:10 | system | system |
4+
| test.c:21:3:21:8 | call to system | Call to banned function $@. | test.c:4:5:4:10 | system | system |
5+
| test.c:22:3:22:7 | call to popen | Call to banned function $@. | test.c:6:7:6:11 | popen | popen |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/ENV33-C/DoNotCallSystem.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/systemused/SystemUsed.ql

c/cert/test/rules/ENV33-C/test.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
typedef struct _FILE FILE;
2+
#define NULL (void *)0
3+
4+
int system(const char *);
5+
void abort(void);
6+
FILE *popen(const char *, const char *);
7+
8+
void f1(const char *p1) {
9+
FILE *l1;
10+
system(p1); // NON_COMPLIANT
11+
abort();
12+
l1 = popen("ls *", "r"); // NON_COMPLIANT
13+
}
14+
15+
void f2() {
16+
const int *l1 = NULL;
17+
18+
system(0); // COMPLIANT
19+
system(NULL); // COMPLIANT
20+
system(l1); // NON_COMPLIANT
21+
system("ls -la"); // NON_COMPLIANT
22+
popen(NULL, NULL); // NON_COMPLIANT
23+
}

c/common/test/includes/standard-library/stdarg.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ extern "C" {
99

1010
#include <bits/alltypes.h>
1111

12-
#define va_start(v,l) __builtin_va_start(v,l)
13-
#define va_end(v) __builtin_va_end(v)
14-
#define va_arg(v,l) __builtin_va_arg(v,l)
15-
#define va_copy(d,s) __builtin_va_copy(d,s)
12+
#define va_start(v, l) __builtin_va_start(v, l)
13+
#define va_end(v) __builtin_va_end(v)
14+
#define va_arg(v, l) __builtin_va_arg(v, l)
15+
#define va_copy(d, s) __builtin_va_copy(d, s)
1616

1717
#ifdef __cplusplus
1818
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.c:6:13:6:22 | ... , ... | Use of banned ',' expression. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.commaoperatorused.CommaOperatorUsed

0 commit comments

Comments
 (0)