Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28fb3d6

Browse files
author
Robert Marsh
committed
C++: add fread and printf alias models
1 parent 52a7471 commit 28fb3d6

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

cpp/ql/src/semmle/code/cpp/models/Models.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
private import implementations.Fread
12
private import implementations.IdentityFunction
23
private import implementations.Inet
34
private import implementations.Memcpy
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import semmle.code.cpp.models.interfaces.Alias
2+
3+
class Fread extends AliasFunction {
4+
Fread() {
5+
this.hasGlobalName("fread")
6+
}
7+
8+
override predicate parameterNeverEscapes(int n) {
9+
n = 0 or
10+
n = 3
11+
}
12+
13+
override predicate parameterEscapesOnlyViaReturn(int n) { none() }
14+
15+
override predicate parameterIsAlwaysReturned(int n) { none() }
16+
}

cpp/ql/src/semmle/code/cpp/models/implementations/Printf.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import semmle.code.cpp.models.interfaces.FormattingFunction
2+
import semmle.code.cpp.models.interfaces.Alias
23

34
/**
45
* The standard functions `printf`, `wprintf` and their glib variants.
56
*/
6-
class Printf extends FormattingFunction {
7+
class Printf extends FormattingFunction, AliasFunction {
78
Printf() {
89
this instanceof TopLevelFunction and
910
(
@@ -22,6 +23,14 @@ class Printf extends FormattingFunction {
2223
hasGlobalOrStdName("wprintf") or
2324
hasGlobalName("wprintf_s")
2425
}
26+
27+
override predicate parameterNeverEscapes(int n) {
28+
n = 0
29+
}
30+
31+
override predicate parameterEscapesOnlyViaReturn(int n) { none() }
32+
33+
override predicate parameterIsAlwaysReturned(int n) { none() }
2534
}
2635

2736
/**

0 commit comments

Comments
 (0)