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

Skip to content

Commit e065466

Browse files
committed
C++: Give Snprintf a proper interface.
1 parent c9f846e commit e065466

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ private class Sprintf extends FormattingFunction {
119119
}
120120

121121
/**
122-
* The standard functions `snprintf` and `swprintf`, and their
123-
* Microsoft and glib variants.
122+
* Implements `Snprintf`.
124123
*/
125-
private class Snprintf extends FormattingFunction {
126-
Snprintf() {
124+
private class SnprintfImpl extends Snprintf {
125+
SnprintfImpl() {
127126
this instanceof TopLevelFunction and
128127
(
129128
hasGlobalOrStdName("snprintf") or // C99 defines snprintf
@@ -180,12 +179,7 @@ private class Snprintf extends FormattingFunction {
180179
)
181180
}
182181

183-
/**
184-
* Holds if this function returns the length of the formatted string
185-
* that would have been output, regardless of the amount of space
186-
* in the buffer.
187-
*/
188-
predicate returnsFullFormatLength() {
182+
override predicate returnsFullFormatLength() {
189183
(
190184
hasGlobalOrStdName("snprintf") or
191185
hasGlobalName("g_snprintf") or

cpp/ql/src/semmle/code/cpp/models/interfaces/FormattingFunction.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,16 @@ abstract class FormattingFunction extends ArrayFunction, TaintFunction {
165165
)
166166
}
167167
}
168+
169+
/**
170+
* The standard functions `snprintf` and `swprintf`, and their
171+
* Microsoft and glib variants.
172+
*/
173+
abstract class Snprintf extends FormattingFunction {
174+
/**
175+
* Holds if this function returns the length of the formatted string
176+
* that would have been output, regardless of the amount of space
177+
* in the buffer.
178+
*/
179+
predicate returnsFullFormatLength() { none() }
180+
}

0 commit comments

Comments
 (0)