Skip to content

Commit 7730f5d

Browse files
committed
C++: Use model interfaces in SafeExternalAPIFunction and make the three previosuly-used implementation models private.
1 parent 65dbb6e commit 7730f5d

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

cpp/ql/src/Security/CWE/CWE-020/SafeExternalAPIFunction.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ abstract class SafeExternalAPIFunction extends Function { }
1313
/** The default set of "safe" external APIs. */
1414
private class DefaultSafeExternalAPIFunction extends SafeExternalAPIFunction {
1515
DefaultSafeExternalAPIFunction() {
16-
// implementation note: this should be based on the properties of public interfaces, rather than accessing implementation classes directly. When we've done that, the three classes referenced here should be made fully private.
17-
this instanceof PureStrFunction or
18-
this instanceof StrLenFunction or
19-
this instanceof PureMemFunction
16+
this instanceof ArrayFunction and
17+
not this.(ArrayFunction).hasArrayOutput(_)
2018
}
2119
}

cpp/ql/src/Security/CWE/CWE-020/ir/SafeExternalAPIFunction.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ abstract class SafeExternalAPIFunction extends Function { }
1313
/** The default set of "safe" external APIs. */
1414
private class DefaultSafeExternalAPIFunction extends SafeExternalAPIFunction {
1515
DefaultSafeExternalAPIFunction() {
16-
// implementation note: this should be based on the properties of public interfaces, rather than accessing implementation classes directly. When we've done that, the three classes referenced here should be made fully private.
17-
this instanceof PureStrFunction or
18-
this instanceof StrLenFunction or
19-
this instanceof PureMemFunction
16+
this instanceof ArrayFunction and
17+
not this.(ArrayFunction).hasArrayOutput(_)
2018
}
2119
}

cpp/ql/src/semmle/code/cpp/models/implementations/Pure.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import semmle.code.cpp.models.interfaces.SideEffect
88
*
99
* INTERNAL: do not use.
1010
*/
11-
class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunction, SideEffectFunction {
11+
private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunction,
12+
SideEffectFunction {
1213
PureStrFunction() {
1314
hasGlobalOrStdName([
1415
"atof", "atoi", "atol", "atoll", "strcasestr", "strchnul", "strchr", "strchrnul", "strstr",
@@ -68,7 +69,7 @@ class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunction, SideE
6869
*
6970
* INTERNAL: do not use.
7071
*/
71-
class StrLenFunction extends AliasFunction, ArrayFunction, SideEffectFunction {
72+
private class StrLenFunction extends AliasFunction, ArrayFunction, SideEffectFunction {
7273
StrLenFunction() {
7374
hasGlobalOrStdName(["strlen", "strnlen", "wcslen"])
7475
or
@@ -123,7 +124,8 @@ private class PureFunction extends TaintFunction, SideEffectFunction {
123124
*
124125
* INTERNAL: do not use.
125126
*/
126-
class PureMemFunction extends AliasFunction, ArrayFunction, TaintFunction, SideEffectFunction {
127+
private class PureMemFunction extends AliasFunction, ArrayFunction, TaintFunction,
128+
SideEffectFunction {
127129
PureMemFunction() { hasGlobalOrStdName(["memchr", "memrchr", "rawmemchr", "memcmp", "memmem"]) }
128130

129131
override predicate hasArrayInput(int bufParam) {

0 commit comments

Comments
 (0)