C++: add fread and printf alias models

This commit is contained in:
Robert Marsh
2019-11-04 16:17:45 -08:00
parent 52a74718da
commit 28fb3d606a
3 changed files with 27 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
private import implementations.Fread
private import implementations.IdentityFunction
private import implementations.Inet
private import implementations.Memcpy

View File

@@ -0,0 +1,16 @@
import semmle.code.cpp.models.interfaces.Alias
class Fread extends AliasFunction {
Fread() {
this.hasGlobalName("fread")
}
override predicate parameterNeverEscapes(int n) {
n = 0 or
n = 3
}
override predicate parameterEscapesOnlyViaReturn(int n) { none() }
override predicate parameterIsAlwaysReturned(int n) { none() }
}

View File

@@ -1,9 +1,10 @@
import semmle.code.cpp.models.interfaces.FormattingFunction
import semmle.code.cpp.models.interfaces.Alias
/**
* The standard functions `printf`, `wprintf` and their glib variants.
*/
class Printf extends FormattingFunction {
class Printf extends FormattingFunction, AliasFunction {
Printf() {
this instanceof TopLevelFunction and
(
@@ -22,6 +23,14 @@ class Printf extends FormattingFunction {
hasGlobalOrStdName("wprintf") or
hasGlobalName("wprintf_s")
}
override predicate parameterNeverEscapes(int n) {
n = 0
}
override predicate parameterEscapesOnlyViaReturn(int n) { none() }
override predicate parameterIsAlwaysReturned(int n) { none() }
}
/**