跳到主要内容

evp_pkey_ctx_new

API 概述

evp_pkey_ctx_newopenssl 中的一个API。该规属于return value check 类型。该规则是使用 Advance 生成的。

规则描述

提示

EVP_PKEY_CTX_new(), EVP_PKEY_CTX_new_id(), EVP_PKEY_CTX_dup() returns either the newly allocated EVP_PKEY_CTX structure of NULL if an error occurred.

信息

标签:return value check

参数下标:N/A

CWE类别:CWE-253

规则代码

import semmle.code.cpp.dataflow.DataFlow
class TestConfiguration extends DataFlow::Configuration {
TestConfiguration() { this = "TestConfiguration" }
override predicate isSource(DataFlow::Node source) {
exists(FunctionCall fc, MacroInvocation mi |
(fc.getTarget().hasQualifiedName("EVP_PKEY_CTX_new") or (
mi.getMacroName() = "EVP_PKEY_CTX_new"
and fc.getTarget().hasName(mi.getMacro().getBody())
)
)
and fc = source.asExpr()
)
}
override predicate isSink(DataFlow::Node sink) {
exists(| sink.asExpr().getEnclosingStmt() instanceof IfStmt
and (sink.asExpr().getParent() instanceof ComparisonOperation
or sink.asExpr().getParent() instanceof NotExpr
or sink.asExpr().getParent() instanceof IfStmt
)
)
}
}
from TestConfiguration cfg, FunctionCall fc, MacroInvocation mi
//function not checked
where (fc.getTarget().hasQualifiedName("EVP_PKEY_CTX_new") or (
mi.getMacroName() = "EVP_PKEY_CTX_new"
and fc.getTarget().hasName(mi.getMacro().getBody())
))
and (
(fc instanceof ExprInVoidContext)
or not exists(Expr source1, Expr sink1|cfg.hasFlow(DataFlow::exprNode(source1), DataFlow::exprNode(sink1)) and fc = source1)
)
select fc.getLocation()