|
5 | 5 | * @kind path-problem |
6 | 6 | * @problem.severity warning |
7 | 7 | * @security-severity 7.5 |
8 | | - * @precision medium |
| 8 | + * @precision high |
9 | 9 | * @id cpp/cleartext-transmission |
10 | 10 | * @tags security |
11 | 11 | * external/cwe/cwe-319 |
|
14 | 14 | import cpp |
15 | 15 | import semmle.code.cpp.security.SensitiveExprs |
16 | 16 | import semmle.code.cpp.dataflow.TaintTracking |
17 | | -import semmle.code.cpp.valuenumbering.GlobalValueNumbering |
18 | 17 | import semmle.code.cpp.models.interfaces.FlowSource |
| 18 | +import semmle.code.cpp.commons.File |
19 | 19 | import DataFlow::PathGraph |
20 | 20 |
|
21 | 21 | /** |
@@ -121,24 +121,32 @@ abstract class NetworkSendRecv extends FunctionCall { |
121 | 121 | NetworkSendRecv() { |
122 | 122 | this.getTarget() = target and |
123 | 123 | // exclude calls based on the socket... |
124 | | - not exists(GVN g | |
125 | | - g = globalValueNumber(target.getSocketExpr(this)) and |
| 124 | + not exists(DataFlow::Node src, DataFlow::Node dest | |
| 125 | + DataFlow::localFlow(src, dest) and |
| 126 | + dest.asExpr() = target.getSocketExpr(this) and |
126 | 127 | ( |
127 | 128 | // literal constant |
128 | | - globalValueNumber(any(Literal l)) = g |
| 129 | + src.asExpr() instanceof Literal |
129 | 130 | or |
130 | 131 | // variable (such as a global) initialized to a literal constant |
131 | 132 | exists(Variable v | |
132 | 133 | v.getInitializer().getExpr() instanceof Literal and |
133 | | - g = globalValueNumber(v.getAnAccess()) |
| 134 | + src.asExpr() = v.getAnAccess() |
134 | 135 | ) |
135 | 136 | or |
136 | 137 | // result of a function call with literal inputs (likely constant) |
| 138 | + forex(Expr arg | arg = src.asExpr().(FunctionCall).getAnArgument() | arg instanceof Literal) |
| 139 | + or |
| 140 | + // variable called `stdin`, `stdout` or `stderr` |
| 141 | + src.asExpr().(VariableAccess).getTarget().getName() = ["stdin", "stdout", "stderr"] |
| 142 | + or |
| 143 | + // open of `"/dev/tty"` |
137 | 144 | exists(FunctionCall fc | |
138 | | - forex(Expr arg | arg = fc.getAnArgument() | arg instanceof Literal) and |
139 | | - g = globalValueNumber(fc) |
| 145 | + fopenCall(fc) and |
| 146 | + fc.getAnArgument().getValue() = "/dev/tty" and |
| 147 | + src.asExpr() = fc |
140 | 148 | ) |
141 | | - // (this is far from exhaustive) |
| 149 | + // (this is not exhaustive) |
142 | 150 | ) |
143 | 151 | ) |
144 | 152 | } |
|
0 commit comments