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

Skip to content

Commit b670e5b

Browse files
authored
C++: Model bsl functions in Printf.qll.
1 parent fd2e029 commit b670e5b

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

  • cpp/ql/src/semmle/code/cpp/models/implementations

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ private class Printf extends FormattingFunction, AliasFunction {
1515
Printf() {
1616
this instanceof TopLevelFunction and
1717
(
18-
hasGlobalOrStdName(["printf", "wprintf"]) or
18+
hasGlobalOrStdishName(["printf", "wprintf"]) or
1919
hasGlobalName(["printf_s", "wprintf_s", "g_printf"])
2020
) and
2121
not exists(getDefinition().getFile().getRelativePath())
2222
}
2323

2424
override int getFormatParameterIndex() { result = 0 }
2525

26-
deprecated override predicate isWideCharDefault() {
27-
hasGlobalOrStdName("wprintf") or
28-
hasGlobalName("wprintf_s")
29-
}
26+
deprecated override predicate isWideCharDefault() { hasName(["wprintf", "wprintf_s"]) }
3027

3128
override predicate isOutputGlobal() { any() }
3229

@@ -44,15 +41,15 @@ private class Fprintf extends FormattingFunction {
4441
Fprintf() {
4542
this instanceof TopLevelFunction and
4643
(
47-
hasGlobalOrStdName(["fprintf", "fwprintf"]) or
44+
hasGlobalOrStdishName(["fprintf", "fwprintf"]) or
4845
hasGlobalName("g_fprintf")
4946
) and
5047
not exists(getDefinition().getFile().getRelativePath())
5148
}
5249

5350
override int getFormatParameterIndex() { result = 1 }
5451

55-
deprecated override predicate isWideCharDefault() { hasGlobalOrStdName("fwprintf") }
52+
deprecated override predicate isWideCharDefault() { hasName("fwprintf") }
5653

5754
override int getOutputParameterIndex(boolean isStream) { result = 0 and isStream = true }
5855
}
@@ -64,7 +61,7 @@ private class Sprintf extends FormattingFunction {
6461
Sprintf() {
6562
this instanceof TopLevelFunction and
6663
(
67-
hasGlobalOrStdName([
64+
hasGlobalOrStdishName([
6865
"sprintf", // sprintf(dst, format, args...)
6966
"wsprintf" // wsprintf(dst, format, args...)
7067
])
@@ -90,22 +87,20 @@ private class Sprintf extends FormattingFunction {
9087
}
9188

9289
override int getFormatParameterIndex() {
93-
hasGlobalName("g_strdup_printf") and result = 0
90+
hasName("g_strdup_printf") and result = 0
9491
or
95-
hasGlobalName("__builtin___sprintf_chk") and result = 3
92+
hasName("__builtin___sprintf_chk") and result = 3
9693
or
9794
not getName() = ["g_strdup_printf", "__builtin___sprintf_chk"] and
9895
result = 1
9996
}
10097

10198
override int getOutputParameterIndex(boolean isStream) {
102-
not hasGlobalName("g_strdup_printf") and result = 0 and isStream = false
99+
not hasName("g_strdup_printf") and result = 0 and isStream = false
103100
}
104101

105102
override int getFirstFormatArgumentIndex() {
106-
if hasGlobalName("__builtin___sprintf_chk")
107-
then result = 4
108-
else result = getNumberOfParameters()
103+
if hasName("__builtin___sprintf_chk") then result = 4 else result = getNumberOfParameters()
109104
}
110105
}
111106

@@ -116,7 +111,7 @@ private class SnprintfImpl extends Snprintf {
116111
SnprintfImpl() {
117112
this instanceof TopLevelFunction and
118113
(
119-
hasGlobalOrStdName([
114+
hasGlobalOrStdishName([
120115
"snprintf", // C99 defines snprintf
121116
"swprintf" // The s version of wide-char printf is also always the n version
122117
])
@@ -163,10 +158,7 @@ private class SnprintfImpl extends Snprintf {
163158
}
164159

165160
override predicate returnsFullFormatLength() {
166-
(
167-
hasGlobalOrStdName("snprintf") or
168-
hasGlobalName(["g_snprintf", "__builtin___snprintf_chk", "snprintf_s"])
169-
) and
161+
hasName(["snprintf", "g_snprintf", "__builtin___snprintf_chk", "snprintf_s"]) and
170162
not exists(getDefinition().getFile().getRelativePath())
171163
}
172164

0 commit comments

Comments
 (0)