13
13
14
14
import cpp
15
15
import semmle.code.cpp.ir.dataflow.DataFlow
16
- import semmle.code.cpp.ir.dataflow.DataFlow2
17
16
18
17
predicate isCreateProcessFunction ( FunctionCall call , int applicationNameIndex , int commandLineIndex ) {
19
18
call .getTarget ( ) .hasGlobalName ( "CreateProcessA" ) and
@@ -55,42 +54,40 @@ class CreateProcessFunctionCall extends FunctionCall {
55
54
/**
56
55
* Dataflow that detects a call to CreateProcess with a NULL value for lpApplicationName argument
57
56
*/
58
- class NullAppNameCreateProcessFunctionConfiguration extends DataFlow:: Configuration {
59
- NullAppNameCreateProcessFunctionConfiguration ( ) {
60
- this = "NullAppNameCreateProcessFunctionConfiguration"
61
- }
62
-
63
- override predicate isSource ( DataFlow:: Node source ) { source .asExpr ( ) instanceof NullValue }
57
+ module NullAppNameCreateProcessFunctionConfiguration implements DataFlow:: ConfigSig {
58
+ predicate isSource ( DataFlow:: Node source ) { source .asExpr ( ) instanceof NullValue }
64
59
65
- override predicate isSink ( DataFlow:: Node sink ) {
60
+ predicate isSink ( DataFlow:: Node sink ) {
66
61
exists ( CreateProcessFunctionCall call , Expr val | val = sink .asExpr ( ) |
67
62
val = call .getArgument ( call .getApplicationNameArgumentId ( ) )
68
63
)
69
64
}
70
65
}
71
66
67
+ module NullAppNameCreateProcessFunction =
68
+ DataFlow:: Make< NullAppNameCreateProcessFunctionConfiguration > ;
69
+
72
70
/**
73
71
* Dataflow that detects a call to CreateProcess with an unquoted commandLine argument
74
72
*/
75
- class QuotedCommandInCreateProcessFunctionConfiguration extends DataFlow2:: Configuration {
76
- QuotedCommandInCreateProcessFunctionConfiguration ( ) {
77
- this = "QuotedCommandInCreateProcessFunctionConfiguration"
78
- }
79
-
80
- override predicate isSource ( DataFlow2:: Node source ) {
73
+ module QuotedCommandInCreateProcessFunctionConfiguration implements DataFlow:: ConfigSig {
74
+ predicate isSource ( DataFlow:: Node source ) {
81
75
exists ( string s |
82
76
s = source .asExpr ( ) .getValue ( ) .toString ( ) and
83
77
not isQuotedOrNoSpaceApplicationNameOnCmd ( s )
84
78
)
85
79
}
86
80
87
- override predicate isSink ( DataFlow2 :: Node sink ) {
81
+ predicate isSink ( DataFlow :: Node sink ) {
88
82
exists ( CreateProcessFunctionCall call , Expr val | val = sink .asExpr ( ) |
89
83
val = call .getArgument ( call .getCommandLineArgumentId ( ) )
90
84
)
91
85
}
92
86
}
93
87
88
+ module QuotedCommandInCreateProcessFunction =
89
+ DataFlow:: Make< QuotedCommandInCreateProcessFunctionConfiguration > ;
90
+
94
91
bindingset [ s]
95
92
predicate isQuotedOrNoSpaceApplicationNameOnCmd ( string s ) {
96
93
s .regexpMatch ( "\"([^\"])*\"[\\s\\S]*" ) // The first element (path) is quoted
@@ -100,14 +97,14 @@ predicate isQuotedOrNoSpaceApplicationNameOnCmd(string s) {
100
97
101
98
from CreateProcessFunctionCall call , string msg1 , string msg2
102
99
where
103
- exists ( Expr appName , NullAppNameCreateProcessFunctionConfiguration nullAppConfig |
100
+ exists ( Expr appName |
104
101
appName = call .getArgument ( call .getApplicationNameArgumentId ( ) ) and
105
- nullAppConfig . hasFlowToExpr ( appName ) and
102
+ NullAppNameCreateProcessFunction :: hasFlowToExpr ( appName ) and
106
103
msg1 = call .toString ( ) + " with lpApplicationName == NULL (" + appName + ")"
107
104
) and
108
- exists ( Expr cmd , QuotedCommandInCreateProcessFunctionConfiguration quotedConfig |
105
+ exists ( Expr cmd |
109
106
cmd = call .getArgument ( call .getCommandLineArgumentId ( ) ) and
110
- quotedConfig . hasFlowToExpr ( cmd ) and
107
+ QuotedCommandInCreateProcessFunction :: hasFlowToExpr ( cmd ) and
111
108
msg2 =
112
109
" and with an unquoted lpCommandLine (" + cmd +
113
110
") introduces a security vulnerability if the path contains spaces."
0 commit comments