Skip to content

Commit 0453c0f

Browse files
committed
C++: Convert to C++ and make it look more like SensitiveExprs.qll.
1 parent ec98269 commit 0453c0f

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed
Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/**
2-
* Provides classes and predicates for identifying private data and methods for security.
2+
* Provides classes for heuristically identifying variables and functions that
3+
* might contain or return sensitive private data.
34
*
4-
* 'Private' data in general is anything that would compromise user privacy if exposed. This
5-
* library tries to guess where private data may either be stored in a variable or produced by a
6-
* method.
5+
* 'Private' data in general is anything that would compromise user privacy if
6+
* exposed. This library tries to guess where private data may either be stored
7+
* in a variable or returned by a function call.
78
*
8-
* This library is not concerned with credentials. See `SensitiveActions` for expressions related
9-
* to credentials.
9+
* This library is not concerned with credentials. See `SensitiveExprs.qll` for
10+
* expressions related to credentials.
1011
*/
1112

12-
import csharp
13-
import semmle.code.csharp.frameworks.system.windows.Forms
13+
import cpp
1414

1515
/** A string for `match` that identifies strings that look like they represent private data. */
1616
private string privateNames() {
@@ -32,35 +32,32 @@ private string privateNames() {
3232
]
3333
}
3434

35-
/** An expression that might contain private data. */
36-
abstract class PrivateDataExpr extends Expr { }
37-
38-
/** A method call that might produce private data. */
39-
class PrivateMethodCall extends PrivateDataExpr, MethodCall {
40-
PrivateMethodCall() {
41-
exists(string s | this.getTarget().getName().toLowerCase() = s | s.matches(privateNames()))
42-
}
43-
}
44-
45-
/** An indexer access that might produce private data. */
46-
class PrivateIndexerAccess extends PrivateDataExpr, IndexerAccess {
47-
PrivateIndexerAccess() {
48-
exists(string s | this.getAnIndex().getValue().toLowerCase() = s | s.matches(privateNames()))
35+
/**
36+
* A variable that might contain sensitive private information.
37+
*/
38+
class PrivateDataVariable extends Variable {
39+
PrivateDataVariable() {
40+
this.getName().toLowerCase().matches(privateNames()) and
41+
not this.getUnspecifiedType() instanceof IntegralType
4942
}
5043
}
5144

52-
/** An access to a variable that might contain private data. */
53-
class PrivateVariableAccess extends PrivateDataExpr, VariableAccess {
54-
PrivateVariableAccess() {
55-
exists(string s | this.getTarget().getName().toLowerCase() = s | s.matches(privateNames()))
45+
/**
46+
* A function that might return sensitive private information.
47+
*/
48+
class PrivateDataFunction extends Function {
49+
PrivateDataFunction() {
50+
this.getName().toLowerCase().matches(privateNames()) and
51+
not this.getUnspecifiedType() instanceof IntegralType
5652
}
5753
}
5854

59-
/** Reading the text property of a control that might contain private data. */
60-
class PrivateControlAccess extends PrivateDataExpr {
61-
PrivateControlAccess() {
62-
exists(TextControl c |
63-
this = c.getARead() and c.getName().toLowerCase().matches(privateNames())
64-
)
55+
/**
56+
* An expression whose value might be sensitive private information.
57+
*/
58+
class PrivateDataExpr extends Expr {
59+
PrivateDataExpr() {
60+
this.(VariableAccess).getTarget() instanceof PrivateDataVariable or
61+
this.(FunctionCall).getTarget() instanceof PrivateDataFunction
6562
}
6663
}

0 commit comments

Comments
 (0)