Merge pull request #736 from geoffw0/macroinv2

CPP: Deprecate MacroInvocationExpr and MacroInvocationStmt
This commit is contained in:
Jonas Jensen
2019-01-25 09:02:02 +01:00
committed by GitHub
7 changed files with 170 additions and 21 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 {

View File

@@ -261,8 +261,13 @@ class MacroInvocation extends MacroAccess {
/**
* A top-level expression generated by a macro invocation.
*
* DEPRECATED: Use `MacroInvocation.getExpr()` directly to get an
* expression generated at the top-level of a macro invocation. Use
* `MacroInvocation.getAnAffectedElement()` to get any element generated
* by a macro invocation.
*/
class MacroInvocationExpr extends Expr {
deprecated class MacroInvocationExpr extends Expr {
MacroInvocationExpr() {
exists(MacroInvocation i | this = i.getExpr())
}
@@ -282,8 +287,13 @@ class MacroInvocationExpr extends Expr {
/**
* A top-level statement generated by a macro invocation.
*
* DEPRECATED: Use `MacroInvocation.getStmt()` directly to get a
* statement generated at the top-level of a macro invocation. Use
* `MacroInvocation.getAnAffectedElement()` to get any element generated
* by a macro invocation.
*/
class MacroInvocationStmt extends Stmt {
deprecated class MacroInvocationStmt extends Stmt {
MacroInvocationStmt() {
exists(MacroInvocation i | this = i.getStmt())
}