Skip to content

Commit d59c808

Browse files
Merge branch 'main' into dependabot/github_actions/actions/checkout-5
2 parents 8c10a17 + 682834c commit d59c808

File tree

136 files changed

+8500
-276
lines changed

Some content is hidden

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

136 files changed

+8500
-276
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| test.c:21:14:21:19 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:13:12:13:17 | call to getenv | call to getenv | test.c:17:13:17:18 | call to getenv | call to getenv |
2-
| test.c:134:14:134:17 | temp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:130:12:130:17 | call to getenv | call to getenv | test.c:131:11:131:16 | call to getenv | call to getenv |
3-
| test.c:134:20:134:22 | tmp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:131:11:131:16 | call to getenv | call to getenv | test.c:130:12:130:17 | call to getenv | call to getenv |
4-
| test.c:165:14:165:26 | tmpvar_global | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:157:19:157:24 | call to getenv | call to getenv | test.c:161:20:161:25 | call to getenv | call to getenv |
5-
| test.c:188:18:188:18 | r | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:185:7:185:15 | call to setlocale | call to setlocale | test.c:187:8:187:17 | call to localeconv | call to localeconv |
6-
| test.c:208:10:208:15 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:202:12:202:17 | call to getenv | call to getenv | test.c:206:3:206:8 | call to f11fun | call to f11fun |
1+
| test.c:21:14:21:19 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the subsequent $@. | test.c:13:12:13:17 | call to getenv | call to getenv | test.c:17:13:17:18 | call to getenv | call to getenv |
2+
| test.c:134:14:134:17 | temp | This pointer was returned by a $@ and may have been overwritten by the subsequent $@. | test.c:130:12:130:17 | call to getenv | call to getenv | test.c:131:11:131:16 | call to getenv | call to getenv |
3+
| test.c:134:20:134:22 | tmp | This pointer was returned by a $@ and may have been overwritten by the subsequent $@. | test.c:131:11:131:16 | call to getenv | call to getenv | test.c:130:12:130:17 | call to getenv | call to getenv |
4+
| test.c:165:14:165:26 | tmpvar_global | This pointer was returned by a $@ and may have been overwritten by the subsequent $@. | test.c:157:19:157:24 | call to getenv | call to getenv | test.c:161:20:161:25 | call to getenv | call to getenv |
5+
| test.c:188:18:188:18 | r | This pointer was returned by a $@ and may have been overwritten by the subsequent $@. | test.c:185:7:185:15 | call to setlocale | call to setlocale | test.c:187:8:187:17 | call to localeconv | call to localeconv |
6+
| test.c:208:10:208:15 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the subsequent $@. | test.c:202:12:202:17 | call to getenv | call to getenv | test.c:206:3:206:8 | call to f11fun | call to f11fun |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A3-9-1` - `VariableWidthIntegerTypesUsed.ql`:
2+
- This query now reports the use of non-fixed width integer types in function return types, with the exception of `char` types and for `main` functions.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `ENV34-C`, `RULE-21-20`, `RULE-25-5-3`: `DoNotStorePointersReturnedByEnvFunctions.ql`, `CallToSetlocaleInvalidatesOldPointers.ql`, `CallToSetlocaleInvalidatesOldPointersMisra.ql`
2+
- Fixed a misspelling of "subsequent" in the alert message.

cpp/autosar/src/codingstandards/cpp/CommonTypes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cpp as default
22

33
/*
4-
* Implementations of the C/C++ Fixed Width Types from cstdint.h.
4+
* Implementations of the C/C++ Fixed Width Types from cstdint.
55
*
66
* TODO: Deprecate once this is available in the CodeQL standard library.
77
*/

cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,10 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20-
import codingstandards.cpp.EncapsulatingFunctions
21-
import codingstandards.cpp.BuiltInNumericTypes
22-
import codingstandards.cpp.Type
23-
import codingstandards.cpp.Operator
20+
import codingstandards.cpp.rules.variablewidthintegertypesused.VariableWidthIntegerTypesUsed
2421

25-
from Variable v, Type typeStrippedOfSpecifiers
26-
where
27-
not isExcluded(v, DeclarationsPackage::variableWidthIntegerTypesUsedQuery()) and
28-
typeStrippedOfSpecifiers = stripSpecifiers(v.getType()) and
29-
(
30-
typeStrippedOfSpecifiers instanceof BuiltInIntegerType or
31-
typeStrippedOfSpecifiers instanceof UnsignedCharType or
32-
typeStrippedOfSpecifiers instanceof SignedCharType
33-
) and
34-
not v instanceof ExcludedVariable and
35-
// Dont consider template instantiations because instantiations with
36-
// Fixed Width Types are recorded after stripping their typedef'd type,
37-
// thereby, causing false positives (#540).
38-
not v.isFromTemplateInstantiation(_) and
39-
//post-increment/post-decrement operators are required by the standard to have a dummy int parameter
40-
not v.(Parameter).getFunction() instanceof PostIncrementOperator and
41-
not v.(Parameter).getFunction() instanceof PostDecrementOperator
42-
select v, "Variable '" + v.getName() + "' has variable-width type."
22+
class VariableWidthIntegerTypesUsedQuery extends VariableWidthIntegerTypesUsedSharedQuery {
23+
VariableWidthIntegerTypesUsedQuery() {
24+
this = DeclarationsPackage::variableWidthIntegerTypesUsedQuery()
25+
}
26+
}

cpp/autosar/test/rules/A3-9-1/VariableWidthIntegerTypesUsed.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/variablewidthintegertypesused/VariableWidthIntegerTypesUsed.ql
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
| test.cpp:4:8:4:8 | c | Variable 'c' has variable-width char type. |
2-
| test.cpp:38:14:38:15 | c1 | Variable 'c1' has variable-width char type. |
3-
| test.cpp:56:17:56:18 | c2 | Variable 'c2' has variable-width char type. |
2+
| test.cpp:10:14:10:15 | c1 | Variable 'c1' has variable-width char type. |
3+
| test.cpp:14:17:14:18 | c2 | Variable 'c2' has variable-width char type. |

cpp/autosar/test/rules/A3-9-1/test.cpp

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,16 @@
22

33
void test_variable_width_type_variables() {
44
char c; // NON_COMPLIANT
5-
unsigned char uc; // NON_COMPLIANT
6-
signed char sc; // NON_COMPLIANT
7-
8-
int i; // NON_COMPLIANT
9-
unsigned int ui; // NON_COMPLIANT
10-
unsigned u; // NON_COMPLIANT
11-
signed int si; // NON_COMPLIANT
12-
signed s; // NON_COMPLIANT
13-
14-
short sh; // NON_COMPLIANT
15-
unsigned short ush; // NON_COMPLIANT
16-
signed short ssh; // NON_COMPLIANT
17-
18-
long l; // NON_COMPLIANT
19-
unsigned long ul; // NON_COMPLIANT
20-
signed long sl; // NON_COMPLIANT
21-
22-
std::int8_t i8; // COMPLIANT
23-
std::int16_t i16; // COMPLIANT
24-
std::int32_t i32; // COMPLIANT
25-
std::int64_t i64; // COMPLIANT
26-
27-
std::uint8_t u8; // COMPLIANT
28-
std::uint16_t u16; // COMPLIANT
29-
std::uint32_t u32; // COMPLIANT
30-
std::uint64_t u64; // COMPLIANT
31-
}
32-
33-
int main(int argc, char *argv[]) { // COMPLIANT
34-
// main as an exception
5+
unsigned char uc; // COMPLIANT - covered by VariableWidthIntegerTypesUsed
6+
signed char sc; // COMPLIANT - covered by VariableWidthIntegerTypesUsed
357
}
368

379
void test_variable_width_type_qualified_variables() {
3810
const char c1 = 0; // NON_COMPLIANT
39-
const unsigned char uc1 = 0; // NON_COMPLIANT
40-
const signed char sc1 = 0; // NON_COMPLIANt
41-
42-
const int i1 = 0; // NON_COMPLIANT
43-
const unsigned int ui1 = 0; // NON_COMPLIANT
44-
const unsigned u1 = 0; // NON_COMPLIANT
45-
const signed int si1 = 0; // NON_COMPLIANT
46-
const signed s1 = 0; // NON_COMPLIANT
47-
48-
const short sh1 = 0; // NON_COMPLIANT
49-
const unsigned short ush1 = 0; // NON_COMPLIANT
50-
const signed short ssh1 = 0; // NON_COMPLIANT
51-
52-
const long l1 = 0; // NON_COMPLIANT
53-
const unsigned long ul1 = 0; // NON_COMPLIANT
54-
const signed long sl1 = 0; // NON_COMPLIANT
11+
const unsigned char uc1 = 0; // COMPLIANT - (VariableWidthIntegerTypesUsed)
12+
const signed char sc1 = 0; // COMPLIANT - (VariableWidthIntegerTypesUsed)
5513

5614
volatile char c2; // NON_COMPLIANT
57-
volatile unsigned char uc2; // NON_COMPLIANT
58-
volatile signed char sc2; // NON_COMPLIANt
59-
60-
volatile int i2; // NON_COMPLIANT
61-
volatile unsigned int ui2; // NON_COMPLIANT
62-
volatile unsigned u2; // NON_COMPLIANT
63-
volatile signed int si2; // NON_COMPLIANT
64-
volatile signed s2; // NON_COMPLIANT
65-
66-
volatile short sh2; // NON_COMPLIANT
67-
volatile unsigned short ush2; // NON_COMPLIANT
68-
volatile signed short ssh2; // NON_COMPLIANT
69-
70-
volatile long l2; // NON_COMPLIANT
71-
volatile unsigned long ul2; // NON_COMPLIANT
72-
volatile signed long sl2; // NON_COMPLIANT
73-
}
74-
75-
struct test_fix_fp_614 {
76-
test_fix_fp_614 operator++(int); // COMPLIANT
77-
test_fix_fp_614 operator--(int); // COMPLIANT
78-
};
79-
80-
// COMPLIANT - instantiated with Fixed Width Types.
81-
template <typename MyType> constexpr void test_fix_fp_540(MyType value) {
82-
value++;
83-
}
84-
85-
int call_test_fix_fp_540() {
86-
test_fix_fp_540<std::uint8_t>(19);
87-
test_fix_fp_540<std::int16_t>(20);
88-
return 0;
89-
}
15+
volatile unsigned char uc2; // COMPLIANT - (VariableWidthIntegerTypesUsed)
16+
volatile signed char sc2; // COMPLIANT - (VariableWidthIntegerTypesUsed)
17+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* A library for supporting the consistent detection of banned functions in C++ code.
3+
*/
4+
5+
import cpp
6+
import AlertReporting
7+
8+
/**
9+
* A signature for a banned function.
10+
*/
11+
signature class BannedFunction extends Function;
12+
13+
/**
14+
* A module for detecting uses of banned functions in C++ code.
15+
*/
16+
module BannedFunctions<BannedFunction F> {
17+
final private class FinalExpr = Expr;
18+
19+
/**
20+
* An expression that uses a banned function.
21+
*
22+
* It can be either a function call or a function access (taking the address of the function).
23+
*/
24+
class UseExpr extends FinalExpr {
25+
string action;
26+
F bannedFunction;
27+
28+
UseExpr() {
29+
this.(FunctionCall).getTarget() = bannedFunction and
30+
action = "Call to"
31+
or
32+
this.(FunctionAccess).getTarget() = bannedFunction and
33+
action = "Address taken for"
34+
}
35+
36+
string getFunctionName() { result = bannedFunction.getName() }
37+
38+
string getAction() { result = action }
39+
40+
Element getPrimaryElement() {
41+
// If this is defined in a macro in the users source location, then report the macro
42+
// expansion, otherwise report the element itself. This ensures that we always report
43+
// the use of the terminating function, but combine usages when the macro is defined
44+
// by the user.
45+
exists(Element e | e = MacroUnwrapper<UseExpr>::unwrapElement(this) |
46+
if exists(e.getFile().getRelativePath()) then result = e else result = this
47+
)
48+
}
49+
}
50+
51+
final private class FinalElement = Element;
52+
53+
/**
54+
* A `Use` of a banned function.
55+
*
56+
* This is an `Element` in a program which represents the use of a banned function.
57+
* For uses within macro expansions, this may report the location of the macro, if
58+
* it is defined within the user's source code.
59+
*/
60+
class Use extends FinalElement {
61+
UseExpr use;
62+
63+
Use() { this = use.getPrimaryElement() }
64+
65+
string getFunctionName() { result = use.getFunctionName() }
66+
67+
string getAction() { result = use.getAction() }
68+
}
69+
}

0 commit comments

Comments
 (0)