-
Notifications
You must be signed in to change notification settings - Fork 66
Package Banned #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Package Banned #13
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
274eb1e
Add package Banned for C
rvermeulen 8518b74
Address incorrect help file formatting
rvermeulen 0d71d6d
Address mismatch expected and actual test results
rvermeulen ba1c8e9
Merge branch 'main' into s-samadi/banned
rvermeulen 783f337
Update Banned package meta data
rvermeulen 3c81723
Merge branch 'main' into s-samadi/banned
rvermeulen 2f6c80a
Merge branch 'main' into s-samadi/banned
rvermeulen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @id c/cert/do-not-call-system | ||
* @name ENV33-C: Do not call system() | ||
* @description Use of the 'system()' function may result in exploitable vulnerabilities. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/cert/id/env33-c | ||
* security | ||
* external/cert/obligtion/rule | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.cert | ||
import semmle.code.cpp.security.CommandExecution | ||
|
||
from FunctionCall call, SystemFunction target | ||
where | ||
not isExcluded(call, BannedPackage::doNotCallSystemQuery()) and | ||
call.getTarget() = target and | ||
// Exclude calls to `system` with a `NULL` pointer, because it is allowed to determine the presence of a command processor. | ||
(target.getName() = "system" implies not call.getAnArgument().(Literal).getValue() = "0") | ||
select call, "Call to banned function $@.", target, target.getName() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
| test.c:10:3:10:8 | call to system | Call to banned function $@. | test.c:4:5:4:10 | system | system | | ||
| test.c:12:8:12:12 | call to popen | Call to banned function $@. | test.c:6:7:6:11 | popen | popen | | ||
| test.c:20:3:20:8 | call to system | Call to banned function $@. | test.c:4:5:4:10 | system | system | | ||
| test.c:21:3:21:8 | call to system | Call to banned function $@. | test.c:4:5:4:10 | system | system | | ||
| test.c:22:3:22:7 | call to popen | Call to banned function $@. | test.c:6:7:6:11 | popen | popen | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rules/ENV33-C/DoNotCallSystem.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c/common/test/rules/systemused/SystemUsed.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
typedef struct _FILE FILE; | ||
#define NULL (void *)0 | ||
|
||
int system(const char *); | ||
void abort(void); | ||
FILE *popen(const char *, const char *); | ||
|
||
void f1(const char *p1) { | ||
FILE *l1; | ||
system(p1); // NON_COMPLIANT | ||
abort(); | ||
l1 = popen("ls *", "r"); // NON_COMPLIANT | ||
} | ||
|
||
void f2() { | ||
const int *l1 = NULL; | ||
|
||
system(0); // COMPLIANT | ||
system(NULL); // COMPLIANT | ||
system(l1); // NON_COMPLIANT | ||
system("ls -la"); // NON_COMPLIANT | ||
popen(NULL, NULL); // NON_COMPLIANT | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
c/common/test/rules/commaoperatorused/CommaOperatorUsed.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| test.c:6:13:6:22 | ... , ... | Use of banned ',' expression. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// GENERATED FILE - DO NOT MODIFY | ||
import codingstandards.cpp.rules.commaoperatorused.CommaOperatorUsed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <stdlib.h> | ||
int f1(); | ||
|
||
void f2() { | ||
int l1 = 10; | ||
int l2 = (l1++, ++l1); // NON_COMPLIANT | ||
f1(); // COMPLIANT | ||
} |
21 changes: 21 additions & 0 deletions
21
c/misra/src/rules/RULE-12-3/CommaOperatorShouldNotBeUsed.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @id c/misra/comma-operator-should-not-be-used | ||
* @name RULE-12-3: The comma operator should not be used | ||
* @description Use of the comma operator may affect the readability of the code. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity recommendation | ||
* @tags external/misra/id/rule-12-3 | ||
* readability | ||
* external/misra/obligation/advisory | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import codingstandards.cpp.rules.commaoperatorused.CommaOperatorUsed | ||
|
||
class CommaOperatorShouldNotBeUsedQuery extends CommaOperatorUsedSharedQuery { | ||
CommaOperatorShouldNotBeUsedQuery() { | ||
this = BannedPackage::commaOperatorShouldNotBeUsedQuery() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @id c/misra/features-of-stdargh-used | ||
* @name RULE-17-1: The features of <stdarg.h> shall not be used | ||
* @description The use of the features of '<stdarg.h> may result in undefined behaviour. | ||
rvermeulen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-17-1 | ||
* correctness | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from Locatable use, string name, string kind | ||
where | ||
not isExcluded(use, BannedPackage::featuresOfStdarghUsedQuery()) and | ||
( | ||
exists(VarArgsExpr va | use = va and name = va.toString() and kind = "built-in operation") | ||
or | ||
exists(Variable v | | ||
v.getType().getName() = "va_list" and | ||
name = "va_list" and | ||
use = v and | ||
kind = "type" | ||
) | ||
) | ||
select use, "Use of banned " + kind + " " + name + "." |
18 changes: 18 additions & 0 deletions
18
c/misra/src/rules/RULE-19-2/UnionKeywordShouldNotBeUsed.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @id c/misra/union-keyword-should-not-be-used | ||
* @name RULE-19-2: The union keyword should not be used | ||
* @description The use of 'union' may result in undefined behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity warning | ||
* @tags external/misra/id/rule-19-2 | ||
* correctness | ||
* external/misra/obligation/advisory | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from Union u | ||
where not isExcluded(u, BannedPackage::unionKeywordShouldNotBeUsedQuery()) | ||
select u, "Use of banned 'union' keyword." |
28 changes: 28 additions & 0 deletions
28
c/misra/src/rules/RULE-21-10/StandardLibraryTimeAndDateFunctionsUsed.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @id c/misra/standard-library-time-and-date-functions-used | ||
* @name RULE-21-10: The Standard Library time and date functions shall not be used | ||
* @description The use of date and time functions may result in undefined behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-21-10 | ||
* correctness | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from Function f, FunctionCall fc | ||
where | ||
not isExcluded(fc, BannedPackage::standardLibraryTimeAndDateFunctionsUsedQuery()) and | ||
( | ||
fc.getTarget() = f and | ||
( | ||
f.getFile().getBaseName() = "time.h" | ||
or | ||
f.getName() = "wcsftime" and | ||
f.getFile().getBaseName() = "wchar.h" | ||
) | ||
) | ||
select fc, "Call to banned function $@.", f, f.getName() |
21 changes: 21 additions & 0 deletions
21
c/misra/src/rules/RULE-21-11/StandardHeaderFileTgmathhUsed.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @id c/misra/standard-header-file-tgmathh-used | ||
* @name RULE-21-11: The standard header file <tgmath.h> shall not be used | ||
* @description The use of the header file '<tgmath.h>' may result in undefined behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-21-11 | ||
* correctness | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from Macro m, MacroInvocation mi | ||
where | ||
not isExcluded(mi, BannedPackage::standardHeaderFileTgmathhUsedQuery()) and | ||
mi.getMacro() = m and | ||
m.getFile().getBaseName() = "tgmath.h" | ||
select mi, "Call to banned macro $@.", m, m.getName() |
53 changes: 53 additions & 0 deletions
53
c/misra/src/rules/RULE-21-12/ExceptionHandlingFeaturesOfFenvhUsed.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @id c/misra/exception-handling-features-of-fenvh-used | ||
* @name RULE-21-12: The exception handling features of <fenv.h> should not be used | ||
* @description The use of the exception handling features of '<fenv.h>' may result in undefined | ||
* behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity warning | ||
* @tags external/misra/id/rule-21-12 | ||
* correctness | ||
* external/misra/obligation/advisory | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
class FPExceptionHandlingFunction extends Function { | ||
FPExceptionHandlingFunction() { | ||
this.hasName([ | ||
"feclearexcept", "fegetexceptflag", "feraiseexcept", "fesetexceptflag", "fetestexcept" | ||
]) and | ||
this.getFile().getBaseName() = "fenv.h" | ||
} | ||
} | ||
|
||
class FPExceptionHandlingMacro extends Macro { | ||
FPExceptionHandlingMacro() { | ||
this.hasName([ | ||
"FE_INEXACT", "FE_DIVBYZERO", "FE_UNDERFLOW", "FE_OVERFLOW", "FE_INVALID", "FE_ALL_EXCEPT" | ||
]) and | ||
this.getFile().getBaseName() = "fenv.h" | ||
} | ||
} | ||
|
||
from Locatable call, Locatable def, string name, string kind | ||
where | ||
not isExcluded(call, BannedPackage::exceptionHandlingFeaturesOfFenvhUsedQuery()) and | ||
( | ||
exists(FPExceptionHandlingFunction f | | ||
def = f and | ||
call = f.getACallToThisFunction() and | ||
name = f.getName() and | ||
kind = "function" | ||
) | ||
or | ||
exists(FPExceptionHandlingMacro m | | ||
def = m and | ||
call = m.getAnInvocation() and | ||
name = m.getName() and | ||
kind = "macro" | ||
) | ||
) | ||
select call, "Call to banned " + kind + " $@.", def, name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @id c/misra/system-of-stdlibh-used | ||
* @name RULE-21-21: The Standard Library function system of <stdlib.h> shall not be used | ||
* @description They use of the 'system()' function from '<stdlib.h> may result in exploitable | ||
* vulnerabilities. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-21-21 | ||
* security | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from FunctionCall call, Function target | ||
where | ||
not isExcluded(call, BannedPackage::systemOfStdlibhUsedQuery()) and | ||
call.getTarget() = target and | ||
target.hasGlobalOrStdName("system") | ||
select call, "Call to banned function $@.", target, target.getName() |
33 changes: 33 additions & 0 deletions
33
c/misra/src/rules/RULE-21-3/MemoryAllocDeallocFunctionsOfStdlibhUsed.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @id c/misra/memory-alloc-dealloc-functions-of-stdlibh-used | ||
* @name RULE-21-3: The memory allocation and deallocation functions of <stdlib.h> shall not be used | ||
* @description The use of memory allocation and deallocation in '<stdlib.h>' may result in | ||
* undefined behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-21-3 | ||
* correctness | ||
* security | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import cpp | ||
import codingstandards.c.misra | ||
import semmle.code.cpp.models.interfaces.Allocation | ||
import semmle.code.cpp.models.interfaces.Deallocation | ||
|
||
from Expr e, string type | ||
where | ||
not isExcluded(e, BannedPackage::memoryAllocDeallocFunctionsOfStdlibhUsedQuery()) and | ||
( | ||
e.(FunctionCall).getTarget().(AllocationFunction).requiresDealloc() and | ||
type = "allocation" | ||
or | ||
e instanceof DeallocationExpr and | ||
not e.(FunctionCall).getTarget() instanceof AllocationFunction and | ||
type = "deallocation" | ||
) | ||
select e, "Use of banned dynamic memory " + type + "." |
46 changes: 46 additions & 0 deletions
46
c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @id c/misra/standard-header-file-used-setjmph | ||
* @name RULE-21-4: The standard header file shall not be used <setjmp.h> | ||
* @description The use of features of '<setjmp.h>' may result in undefined behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-21-4 | ||
* correctness | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
class SetJmp extends Macro { | ||
SetJmp() { | ||
this.hasName("setjmp") and | ||
this.getFile().getAbsolutePath().matches("%setjmp.h") | ||
} | ||
} | ||
|
||
class LongJmp extends Function { | ||
LongJmp() { | ||
this.hasName("longjmp") and | ||
this.getFile().getAbsolutePath().matches("%setjmp.h") | ||
} | ||
} | ||
|
||
from Locatable use, Locatable feature, string name | ||
where | ||
not isExcluded(use, BannedPackage::standardHeaderFileUsedSetjmphQuery()) and | ||
( | ||
exists(SetJmp setjmp | | ||
feature = setjmp and | ||
use = setjmp.getAnInvocation() and | ||
name = "setjmp" | ||
) | ||
or | ||
exists(LongJmp longjmp | | ||
feature = longjmp and | ||
use = longjmp.getACallToThisFunction() and | ||
name = "longjmp" | ||
) | ||
) | ||
select use, "Use of $@.", feature, name |
21 changes: 21 additions & 0 deletions
21
c/misra/src/rules/RULE-21-5/StandardHeaderFileUsedSignalh.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @id c/misra/standard-header-file-used-signalh | ||
* @name RULE-21-5: The standard header file shall not be used <signal.h> | ||
* @description The use of features of '<signal.h>' may result in undefined behaviour. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/misra/id/rule-21-5 | ||
* correctness | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
|
||
from Function f, FunctionCall fc | ||
where | ||
not isExcluded(fc, BannedPackage::standardHeaderFileUsedSignalhQuery()) and | ||
fc.getTarget() = f and | ||
f.getFile().getBaseName() = "signal.h" | ||
select fc, "Call to banned function $@.", f, f.getName() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.