Skip to content

Commit d6049cd

Browse files
committed
C++: Add additional implementations of NonThrowingFunction and make minor fixes to docs
1 parent d9dbcdb commit d6049cd

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import semmle.code.cpp.models.interfaces.FormattingFunction
99
import semmle.code.cpp.models.interfaces.Alias
1010
import semmle.code.cpp.models.interfaces.SideEffect
11+
import semmle.code.cpp.models.interfaces.NonThrowing
1112

1213
/**
1314
* The standard functions `printf`, `wprintf` and their glib variants.
1415
*/
15-
private class Printf extends FormattingFunction, AliasFunction {
16+
private class Printf extends FormattingFunction, AliasFunction, NonThrowingFunction {
1617
Printf() {
1718
this instanceof TopLevelFunction and
1819
(
@@ -36,7 +37,7 @@ private class Printf extends FormattingFunction, AliasFunction {
3637
/**
3738
* The standard functions `fprintf`, `fwprintf` and their glib variants.
3839
*/
39-
private class Fprintf extends FormattingFunction {
40+
private class Fprintf extends FormattingFunction, NonThrowingFunction {
4041
Fprintf() {
4142
this instanceof TopLevelFunction and
4243
(
@@ -54,7 +55,7 @@ private class Fprintf extends FormattingFunction {
5455
/**
5556
* The standard function `sprintf` and its Microsoft and glib variants.
5657
*/
57-
private class Sprintf extends FormattingFunction {
58+
private class Sprintf extends FormattingFunction, NonThrowingFunction {
5859
Sprintf() {
5960
this instanceof TopLevelFunction and
6061
(
@@ -97,7 +98,7 @@ private class Sprintf extends FormattingFunction {
9798
/**
9899
* Implements `Snprintf`.
99100
*/
100-
private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction {
101+
private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction, NonThrowingFunction {
101102
SnprintfImpl() {
102103
this instanceof TopLevelFunction and
103104
(
@@ -172,7 +173,7 @@ private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction {
172173
* and
173174
* https://learn.microsoft.com/en-us/previous-versions/windows/embedded/ms860435(v=msdn.10)
174175
*/
175-
private class StringCchPrintf extends FormattingFunction {
176+
private class StringCchPrintf extends FormattingFunction, NonThrowingFunction {
176177
StringCchPrintf() {
177178
this instanceof TopLevelFunction and
178179
exists(string baseName |
@@ -204,7 +205,7 @@ private class StringCchPrintf extends FormattingFunction {
204205
/**
205206
* The standard function `syslog`.
206207
*/
207-
private class Syslog extends FormattingFunction {
208+
private class Syslog extends FormattingFunction, NonThrowingFunction {
208209
Syslog() {
209210
this instanceof TopLevelFunction and
210211
this.hasGlobalName("syslog") and

cpp/ql/lib/semmle/code/cpp/models/implementations/Strcat.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import semmle.code.cpp.models.interfaces.ArrayFunction
77
import semmle.code.cpp.models.interfaces.DataFlow
88
import semmle.code.cpp.models.interfaces.Taint
99
import semmle.code.cpp.models.interfaces.SideEffect
10+
import semmle.code.cpp.models.interfaces.NonThrowing
1011

1112
/**
1213
* The standard function `strcat` and its wide, sized, and Microsoft variants.
1314
*
1415
* Does not include `strlcat`, which is covered by `StrlcatFunction`
1516
*/
16-
class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, SideEffectFunction {
17+
class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, SideEffectFunction,
18+
NonThrowingFunction
19+
{
1720
StrcatFunction() {
1821
this.hasGlobalOrStdOrBslName([
1922
"strcat", // strcat(dst, src)

cpp/ql/lib/semmle/code/cpp/models/implementations/Strcpy.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import semmle.code.cpp.models.interfaces.ArrayFunction
77
import semmle.code.cpp.models.interfaces.DataFlow
88
import semmle.code.cpp.models.interfaces.Taint
99
import semmle.code.cpp.models.interfaces.SideEffect
10+
import semmle.code.cpp.models.interfaces.NonThrowing
1011

1112
/**
1213
* The standard function `strcpy` and its wide, sized, and Microsoft variants.
1314
*/
14-
class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, SideEffectFunction {
15+
class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, SideEffectFunction,
16+
NonThrowingFunction
17+
{
1518
StrcpyFunction() {
1619
this.hasGlobalOrStdOrBslName([
1720
"strcpy", // strcpy(dst, src)

cpp/ql/lib/semmle/code/cpp/models/interfaces/NonThrowing.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
2-
* Provides an abstract class for modeling functions that never throws.
3-
*
4-
* See also `ThrowingFunction` for modeling functions that do throw.
2+
* Provides an abstract class for modeling functions that never throw.
53
*/
64

75
import semmle.code.cpp.Function

0 commit comments

Comments
 (0)