C++: Replace hasQualifiedName by hasGlobalName in docs examples

This commit is contained in:
Jeroen Ketema
2023-03-03 15:08:00 +01:00
parent f6ce27075c
commit fe5fbaa142
7 changed files with 20 additions and 20 deletions

View File

@@ -2,7 +2,7 @@ import cpp
import semmle.code.cpp.dataflow.new.DataFlow
class GetenvSource extends DataFlow::Node {
GetenvSource() { this.asIndirectExpr(1).(FunctionCall).getTarget().hasQualifiedName("getenv") }
GetenvSource() { this.asIndirectExpr(1).(FunctionCall).getTarget().hasGlobalName("getenv") }
}
class GetenvToGethostbynameConfiguration extends DataFlow::Configuration {

View File

@@ -3,7 +3,7 @@ import semmle.code.cpp.dataflow.new.DataFlow
from Function fopen, FunctionCall fc, Expr src, DataFlow::Node source, DataFlow::Node sink
where
fopen.hasQualifiedName("fopen") and
fopen.hasGlobalName("fopen") and
fc.getTarget() = fopen and
source.asIndirectExpr(1) = src and
sink.asIndirectExpr(1) = fc.getArgument(0) and

View File

@@ -7,14 +7,14 @@ class EnvironmentToFileConfiguration extends DataFlow::Configuration {
override predicate isSource(DataFlow::Node source) {
exists(Function getenv |
source.asIndirectExpr(1).(FunctionCall).getTarget() = getenv and
getenv.hasQualifiedName("getenv")
getenv.hasGlobalName("getenv")
)
}
override predicate isSink(DataFlow::Node sink) {
exists(FunctionCall fc |
sink.asIndirectExpr(1) = fc.getArgument(0) and
fc.getTarget().hasQualifiedName("fopen")
fc.getTarget().hasGlobalName("fopen")
)
}
}

View File

@@ -3,7 +3,7 @@ import semmle.code.cpp.dataflow.new.DataFlow
from Function fopen, FunctionCall fc, Parameter p, DataFlow::Node source, DataFlow::Node sink
where
fopen.hasQualifiedName("fopen") and
fopen.hasGlobalName("fopen") and
fc.getTarget() = fopen and
source.asParameter(1) = p and
sink.asIndirectExpr(1) = fc.getArgument(0) and

View File

@@ -2,6 +2,6 @@ import cpp
from Function fopen, FunctionCall fc
where
fopen.hasQualifiedName("fopen") and
fopen.hasGlobalName("fopen") and
fc.getTarget() = fopen
select fc.getArgument(0)

View File

@@ -97,7 +97,7 @@ The following query finds the filename passed to ``fopen``.
from Function fopen, FunctionCall fc
where
fopen.hasQualifiedName("fopen") and
fopen.hasGlobalName("fopen") and
fc.getTarget() = fopen
select fc.getArgument(0)
@@ -110,7 +110,7 @@ Unfortunately, this will only give the expression in the argument, not the value
from Function fopen, FunctionCall fc, Expr src, DataFlow::Node source, DataFlow::Node sink
where
fopen.hasQualifiedName("fopen") and
fopen.hasGlobalName("fopen") and
fc.getTarget() = fopen and
source.asIndirectExpr(1) = src and
sink.asIndirectExpr(1) = fc.getArgument(0) and
@@ -126,7 +126,7 @@ Then we can vary the source and, for example, use the parameter of a function. T
from Function fopen, FunctionCall fc, Parameter p, DataFlow::Node source, DataFlow::Node sink
where
fopen.hasQualifiedName("fopen") and
fopen.hasGlobalName("fopen") and
fc.getTarget() = fopen and
source.asParameter(1) = p and
sink.asIndirectExpr(1) = fc.getArgument(0) and
@@ -253,14 +253,14 @@ The following data flow configuration tracks data flow from environment variable
override predicate isSource(DataFlow::Node source) {
exists(Function getenv |
source.asIndirectExpr(1).(FunctionCall).getTarget() = getenv and
getenv.hasQualifiedName("getenv")
getenv.hasGlobalName("getenv")
)
}
override predicate isSink(DataFlow::Node sink) {
exists(FunctionCall fc |
sink.asIndirectExpr(1) = fc.getArgument(0) and
fc.getTarget().hasQualifiedName("fopen")
fc.getTarget().hasGlobalName("fopen")
)
}
}
@@ -386,7 +386,7 @@ Exercise 3
import semmle.code.cpp.dataflow.new.DataFlow
class GetenvSource extends DataFlow::Node {
GetenvSource() { this.asIndirectExpr(1).(FunctionCall).getTarget().hasQualifiedName("getenv") }
GetenvSource() { this.asIndirectExpr(1).(FunctionCall).getTarget().hasGlobalName("getenv") }
}
Exercise 4
@@ -398,7 +398,7 @@ Exercise 4
import semmle.code.cpp.dataflow.new.DataFlow
class GetenvSource extends DataFlow::Node {
GetenvSource() { this.asIndirectExpr(1).(FunctionCall).getTarget().hasQualifiedName("getenv") }
GetenvSource() { this.asIndirectExpr(1).(FunctionCall).getTarget().hasGlobalName("getenv") }
}
class GetenvToGethostbynameConfiguration extends DataFlow::Configuration {

View File

@@ -88,7 +88,7 @@ The following query finds the filename passed to ``fopen``.
import cpp
from Function fopen, FunctionCall fc
where fopen.hasQualifiedName("fopen")
where fopen.hasGlobalName("fopen")
and fc.getTarget() = fopen
select fc.getArgument(0)
@@ -100,7 +100,7 @@ Unfortunately, this will only give the expression in the argument, not the value
import semmle.code.cpp.dataflow.DataFlow
from Function fopen, FunctionCall fc, Expr src
where fopen.hasQualifiedName("fopen")
where fopen.hasGlobalName("fopen")
and fc.getTarget() = fopen
and DataFlow::localFlow(DataFlow::exprNode(src), DataFlow::exprNode(fc.getArgument(0)))
select src
@@ -113,7 +113,7 @@ Then we can vary the source and, for example, use the parameter of a function. T
import semmle.code.cpp.dataflow.DataFlow
from Function fopen, FunctionCall fc, Parameter p
where fopen.hasQualifiedName("fopen")
where fopen.hasGlobalName("fopen")
and fc.getTarget() = fopen
and DataFlow::localFlow(DataFlow::parameterNode(p), DataFlow::exprNode(fc.getArgument(0)))
select p
@@ -236,14 +236,14 @@ The following data flow configuration tracks data flow from environment variable
override predicate isSource(DataFlow::Node source) {
exists (Function getenv |
source.asExpr().(FunctionCall).getTarget() = getenv and
getenv.hasQualifiedName("getenv")
getenv.hasGlobalName("getenv")
)
}
override predicate isSink(DataFlow::Node sink) {
exists (FunctionCall fc |
sink.asExpr() = fc.getArgument(0) and
fc.getTarget().hasQualifiedName("fopen")
fc.getTarget().hasGlobalName("fopen")
)
}
}
@@ -356,7 +356,7 @@ Exercise 3
class GetenvSource extends FunctionCall {
GetenvSource() {
this.getTarget().hasQualifiedName("getenv")
this.getTarget().hasGlobalName("getenv")
}
}
@@ -369,7 +369,7 @@ Exercise 4
class GetenvSource extends DataFlow::Node {
GetenvSource() {
this.asExpr().(FunctionCall).getTarget().hasQualifiedName("getenv")
this.asExpr().(FunctionCall).getTarget().hasGlobalName("getenv")
}
}