Skip to content

Commit 8fdea49

Browse files
committed
Convert MSC33-C to the new dataflow library
As it is the dataflow used by `asctime` that is relevant, and not the pointer, use the indirect expression.
1 parent c5c6c58 commit 8fdea49

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

c/cert/src/rules/MSC33-C/DoNotPassInvalidDataToTheAsctimeFunction.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import cpp
2121
import codingstandards.c.cert
22-
import semmle.code.cpp.dataflow.DataFlow
22+
import semmle.code.cpp.dataflow.new.DataFlow
2323

2424
/**
2525
* The argument of a call to `asctime`
@@ -29,6 +29,8 @@ class AsctimeArg extends Expr {
2929
this =
3030
any(FunctionCall f | f.getTarget().hasGlobalName(["asctime", "asctime_r"])).getArgument(0)
3131
}
32+
33+
DataFlow::Node asSink() { this = result.asIndirectExpr() }
3234
}
3335

3436
/**
@@ -37,20 +39,20 @@ class AsctimeArg extends Expr {
3739
*/
3840
module TmStructSafeConfig implements DataFlow::ConfigSig {
3941
predicate isSource(DataFlow::Node src) {
40-
src.asExpr()
42+
src.asIndirectExpr()
4143
.(FunctionCall)
4244
.getTarget()
4345
.hasGlobalName(["localtime", "localtime_r", "localtime_s", "gmtime", "gmtime_r", "gmtime_s"])
4446
}
4547

46-
predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof AsctimeArg }
48+
predicate isSink(DataFlow::Node sink) { exists(AsctimeArg arg | arg.asSink() = sink) }
4749
}
4850

4951
module TmStructSafeFlow = DataFlow::Global<TmStructSafeConfig>;
5052

5153
from AsctimeArg fc
5254
where
5355
not isExcluded(fc, Contracts7Package::doNotPassInvalidDataToTheAsctimeFunctionQuery()) and
54-
not TmStructSafeFlow::flowToExpr(fc)
56+
not TmStructSafeFlow::flowTo(fc.asSink())
5557
select fc,
5658
"The function `asctime` and `asctime_r` should be discouraged. Unsanitized input can overflow the output buffer."

0 commit comments

Comments
 (0)