CPP: Update our uses of MacroInvocationExpr.

This commit is contained in:
Geoffrey White
2018-12-13 11:45:14 +00:00
parent b59c2868cd
commit 6088ca5d5b
4 changed files with 29 additions and 17 deletions

View File

@@ -55,8 +55,11 @@ predicate stringArray(Variable arr, AggregateLiteral init) {
// overwrite some of them with untrusted data.
}
predicate underscoreMacro(MacroInvocationExpr e) {
e.getMacroName() = "_"
predicate underscoreMacro(Expr e) {
exists(MacroInvocation mi |
mi.getMacroName() = "_" and
mi.getExpr() = e
)
}
/**

View File

@@ -18,9 +18,9 @@ import semmle.code.cpp.security.TaintTracking
predicate isRandValue(Expr e) {
e.(FunctionCall).getTarget().getName() = "rand" or
exists(FunctionCall fc |
fc = e.(MacroInvocationExpr).getInvocation().getExpr().getAChild*()
| fc.getTarget().getName() = "rand"
exists(MacroInvocation mi |
e = mi.getExpr() and
e.getAChild*().(FunctionCall).getTarget().getName() = "rand"
)
}

View File

@@ -18,19 +18,29 @@ import semmle.code.cpp.security.Overflow
import semmle.code.cpp.security.Security
import semmle.code.cpp.security.TaintTracking
predicate isMaxValue(MacroInvocationExpr mie) {
mie.getMacroName() = "CHAR_MAX" or
mie.getMacroName() = "LLONG_MAX" or
mie.getMacroName() = "INT_MAX" or
mie.getMacroName() = "SHRT_MAX" or
mie.getMacroName() = "UINT_MAX"
predicate isMaxValue(Expr mie) {
exists(MacroInvocation mi |
mi.getExpr() = mie and
(
mi.getMacroName() = "CHAR_MAX" or
mi.getMacroName() = "LLONG_MAX" or
mi.getMacroName() = "INT_MAX" or
mi.getMacroName() = "SHRT_MAX" or
mi.getMacroName() = "UINT_MAX"
)
)
}
predicate isMinValue(MacroInvocationExpr mie) {
mie.getMacroName() = "CHAR_MIN" or
mie.getMacroName() = "LLONG_MIN" or
mie.getMacroName() = "INT_MIN" or
mie.getMacroName() = "SHRT_MIN"
predicate isMinValue(Expr mie) {
exists(MacroInvocation mi |
mi.getExpr() = mie and
(
mi.getMacroName() = "CHAR_MIN" or
mi.getMacroName() = "LLONG_MIN" or
mi.getMacroName() = "INT_MIN" or
mi.getMacroName() = "SHRT_MIN"
)
)
}
class SecurityOptionsArith extends SecurityOptions {