-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into codeql/upgrade-to-2.16.6
- Loading branch information
Showing
24 changed files
with
410 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,33 +1,44 @@ | ||
import cpp | ||
import codingstandards.cpp.Pointers | ||
import codingstandards.cpp.UndefinedBehavior | ||
|
||
/** | ||
* Library for modeling undefined behavior. | ||
*/ | ||
abstract class CUndefinedBehavior extends UndefinedBehavior { } | ||
|
||
/** | ||
* A function which has the signature - but not the name - of a main function. | ||
*/ | ||
class C99MainFunction extends Function { | ||
C99MainFunction() { | ||
this.getNumberOfParameters() = 2 and | ||
this.getType() instanceof IntType and | ||
this.getParameter(0).getType() instanceof IntType and | ||
this.getParameter(1).getType().(PointerType).getBaseType().(PointerType).getBaseType() | ||
instanceof CharType | ||
this.getType().getUnderlyingType() instanceof IntType and | ||
this.getParameter(0).getType().getUnderlyingType() instanceof IntType and | ||
this.getParameter(1) | ||
.getType() | ||
.getUnderlyingType() | ||
.(UnspecifiedPointerOrArrayType) | ||
.getBaseType() | ||
.(UnspecifiedPointerOrArrayType) | ||
.getBaseType() instanceof CharType | ||
or | ||
this.getNumberOfParameters() = 0 and | ||
this.getType() instanceof VoidType | ||
// Must be explicitly declared as `int main(void)`. | ||
this.getADeclarationEntry().hasVoidParamList() and | ||
this.getType().getUnderlyingType() instanceof IntType | ||
} | ||
} | ||
|
||
class CUndefinedMainDefinition extends CUndefinedBehavior, Function { | ||
CUndefinedMainDefinition() { | ||
// for testing purposes, we use the prefix ____codeql_coding_standards` | ||
(this.getName() = "main" or this.getName().indexOf("____codeql_coding_standards") = 0) and | ||
(this.getName() = "main" or this.getName().indexOf("____codeql_coding_standards_main") = 0) and | ||
not this instanceof C99MainFunction | ||
} | ||
|
||
override string getReason() { | ||
result = | ||
"The behavior of the program is undefined because the main function is not defined according to the C standard." | ||
"main function may trigger undefined behavior because it is not in one of the formats specified by the C standard." | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
13 changes: 8 additions & 5 deletions
13
c/misra/test/rules/RULE-1-3/OccurrenceOfUndefinedBehavior.expected
This file contains 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
| test.c:8:6:8:35 | ____codeql_coding_standards_m2 | May result in undefined behavior. | | ||
| test.c:11:5:11:34 | ____codeql_coding_standards_m3 | May result in undefined behavior. | | ||
| test.c:15:5:15:34 | ____codeql_coding_standards_m4 | May result in undefined behavior. | | ||
| test.c:19:5:19:34 | ____codeql_coding_standards_m5 | May result in undefined behavior. | | ||
| test.c:23:5:23:34 | ____codeql_coding_standards_m6 | May result in undefined behavior. | | ||
| test.c:4:6:4:38 | ____codeql_coding_standards_main1 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:8:5:8:37 | ____codeql_coding_standards_main2 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:27:5:27:37 | ____codeql_coding_standards_main6 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:32:6:32:38 | ____codeql_coding_standards_main7 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:36:5:36:37 | ____codeql_coding_standards_main8 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:40:5:40:37 | ____codeql_coding_standards_main9 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:44:5:44:38 | ____codeql_coding_standards_main10 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | | ||
| test.c:48:5:48:38 | ____codeql_coding_standards_main11 | main function may trigger undefined behavior because it is not in one of the formats specified by the C standard. | |
This file contains 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 |
---|---|---|
@@ -1,25 +1,50 @@ | ||
void main(void) { // COMPLIANT | ||
int main(void) { // COMPLIANT | ||
} | ||
|
||
int ____codeql_coding_standards_m1(int argc, char **argv) { // NON_COMPLIANT | ||
void ____codeql_coding_standards_main1(void) { // NON_COMPLIANT | ||
return 0; | ||
} | ||
|
||
void ____codeql_coding_standards_m2(char *argc, char **argv) { // NON_COMPLIANT | ||
int ____codeql_coding_standards_main2() { // NON_COMPLIANT | ||
return 0; | ||
} | ||
|
||
int ____codeql_coding_standards_main3(int argc, char **argv) { // COMPLIANT | ||
return 0; | ||
} | ||
|
||
int ____codeql_coding_standards_main4(int argc, char argv[][]) { // COMPLIANT | ||
return 0; | ||
} | ||
|
||
int ____codeql_coding_standards_main5(int argc, char *argv[]) { // COMPLIANT | ||
return 0; | ||
} | ||
|
||
typedef int MY_INT; | ||
typedef char *MY_CHAR_PTR; | ||
|
||
int ____codeql_coding_standards_main6(MY_INT argc, | ||
MY_CHAR_PTR argv[]) { // COMPLIANT | ||
return 0; | ||
} | ||
|
||
void ____codeql_coding_standards_main7(char *argc, | ||
char **argv) { // NON_COMPLIANT | ||
} | ||
|
||
int ____codeql_coding_standards_m3(int argc, char *argv) { // NON_COMPLIANT | ||
int ____codeql_coding_standards_main8(int argc, char *argv) { // NON_COMPLIANT | ||
return 0; | ||
} | ||
|
||
int ____codeql_coding_standards_m4() { // NON_COMPLIANT | ||
int ____codeql_coding_standards_main9() { // NON_COMPLIANT | ||
return 0; | ||
} | ||
|
||
int ____codeql_coding_standards_m5(int argc, int *argv) { // NON_COMPLIANT | ||
int ____codeql_coding_standards_main10(int argc, int *argv) { // NON_COMPLIANT | ||
return 0; | ||
} | ||
|
||
int ____codeql_coding_standards_m6(int argc, int **argv) { // NON_COMPLIANT | ||
int ____codeql_coding_standards_main11(int argc, int **argv) { // NON_COMPLIANT | ||
return 0; | ||
} |
4 changes: 3 additions & 1 deletion
4
c/misra/test/rules/RULE-5-4/MacroIdentifiersNotDistinct.expected
This file contains 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
| header3.h:7:1:7:24 | #define MULTIPLE_INCLUDE | Definition of macro MULTIPLE_INCLUDE is not distinct from alternative definition of $@ in rules/RULE-5-4/header4.h. | header4.h:1:1:1:24 | #define MULTIPLE_INCLUDE | MULTIPLE_INCLUDE | | ||
| header3.h:14:1:14:21 | #define NOT_PROTECTED | Definition of macro NOT_PROTECTED is not distinct from alternative definition of $@ in rules/RULE-5-4/header4.h. | header4.h:12:1:12:23 | #define NOT_PROTECTED 1 | NOT_PROTECTED | | ||
| test.c:2:1:2:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | Macro identifer iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB is nondistinct in first 63 characters, compared to $@. | test.c:1:1:1:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | | ||
| test.c:8:1:8:31 | #define FUNCTION_MACRO(X) X + 1 | Macro identifer FUNCTION_MACRO is nondistinct in first 63 characters, compared to $@. | test.c:7:1:7:57 | #define FUNCTION_MACRO(FUNCTION_MACRO) FUNCTION_MACRO + 1 | FUNCTION_MACRO | | ||
| test.c:8:1:8:31 | #define FUNCTION_MACRO(X) X + 1 | Definition of macro FUNCTION_MACRO is not distinct from alternative definition of $@ in rules/RULE-5-4/test.c. | test.c:7:1:7:57 | #define FUNCTION_MACRO(FUNCTION_MACRO) FUNCTION_MACRO + 1 | FUNCTION_MACRO | |
This file contains 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,11 @@ | ||
#ifdef FOO | ||
#include "header1.h" | ||
#else | ||
#include "header2.h" | ||
#endif | ||
|
||
#ifdef FOO | ||
#define A_MACRO 1 // COMPLIANT | ||
#else | ||
#define A_MACRO 2 // COMPLIANT | ||
#endif |
This file contains 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 @@ | ||
#define REPEATED 11 // COMPLIANT |
This file contains 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 @@ | ||
#define REPEATED 1 // COMPLIANT |
This file contains 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,16 @@ | ||
#ifndef HEADER3_H | ||
#define HEADER3_H | ||
|
||
// We should ignore the header guards in this file | ||
|
||
// This is defined unconditionally by both header3.h and header4.h | ||
#define MULTIPLE_INCLUDE // NON_COMPLIANT | ||
|
||
// This is redefined in header3.h, but only if it isn't already defined | ||
#define PROTECTED // COMPLIANT | ||
|
||
// This is redefined in header3.h, but is conditional on some other condition, | ||
// so this is redefined | ||
#define NOT_PROTECTED // NON_COMPLIANT | ||
|
||
#endif |
This file contains 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,13 @@ | ||
#define MULTIPLE_INCLUDE // NON_COMPLIANT | ||
|
||
// This case is triggered from root2.c | ||
// because PROTECTED isn't defined in | ||
// that case | ||
#ifndef PROTECTED | ||
#define PROTECTED // COMPLIANT - checked by guard | ||
#endif | ||
|
||
// Always enabled, so conflicts in root1.c case | ||
#ifdef MULTIPLE_INCLUDE | ||
#define NOT_PROTECTED 1 // NON_COMPLIANT | ||
#endif |
This file contains 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,6 @@ | ||
#define FOO 1 | ||
#include "conditional.h" | ||
|
||
// Both headers define MULTIPLE_INCLUDE | ||
#include "header3.h" | ||
#include "header4.h" |
This file contains 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,3 @@ | ||
#include "conditional.h" | ||
|
||
#include "header4.h" |
This file contains 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
Oops, something went wrong.