Skip to content

Commit 9c4030e

Browse files
authored
Merge pull request #18014 from microsoft/brodes/seh_flow_phase1_throwing_models
Brodes/seh flow phase1 throwing models
2 parents f2d457d + e6641e7 commit 9c4030e

File tree

12 files changed

+39
-17
lines changed

12 files changed

+39
-17
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: deprecated
3+
---
4+
* The `NonThrowing` class (`semmle.code.cpp.models.interfaces.NonThrowing`) has been deprecated. Please use the `NonCppThrowingFunction` class instead.

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,14 @@ class TranslatedFunctionCall extends TranslatedCallExpr, TranslatedDirectCall {
364364

365365
final override predicate mayThrowException() {
366366
expr.getTarget().(ThrowingFunction).mayThrowException(_)
367+
or
368+
expr.getTarget() instanceof AlwaysSehThrowingFunction
367369
}
368370

369371
final override predicate mustThrowException() {
370372
expr.getTarget().(ThrowingFunction).mayThrowException(true)
373+
or
374+
expr.getTarget() instanceof AlwaysSehThrowingFunction
371375
}
372376
}
373377

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import semmle.code.cpp.models.interfaces.NonThrowing
1616
* `__builtin___memcpy_chk`.
1717
*/
1818
private class MemcpyFunction extends ArrayFunction, DataFlowFunction, SideEffectFunction,
19-
AliasFunction, NonThrowingFunction
19+
AliasFunction, NonCppThrowingFunction
2020
{
2121
MemcpyFunction() {
2222
// memcpy(dest, src, num)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import semmle.code.cpp.models.interfaces.SideEffect
1111
import semmle.code.cpp.models.interfaces.NonThrowing
1212

1313
private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, AliasFunction,
14-
SideEffectFunction, NonThrowingFunction
14+
SideEffectFunction, NonCppThrowingFunction
1515
{
1616
MemsetFunctionModel() {
1717
this.hasGlobalOrStdOrBslName("memset")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import semmle.code.cpp.models.interfaces.NonThrowing
66
*
77
* Note: The `throw` specifier was deprecated in C++11 and removed in C++17.
88
*/
9-
class NoexceptFunction extends NonThrowingFunction {
9+
class NoexceptFunction extends NonCppThrowingFunction {
1010
NoexceptFunction() { this.isNoExcept() or this.isNoThrow() }
1111
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import semmle.code.cpp.models.interfaces.NonThrowing
1313
/**
1414
* The standard functions `printf`, `wprintf` and their glib variants.
1515
*/
16-
private class Printf extends FormattingFunction, AliasFunction, NonThrowingFunction {
16+
private class Printf extends FormattingFunction, AliasFunction, NonCppThrowingFunction {
1717
Printf() {
1818
this instanceof TopLevelFunction and
1919
(
@@ -37,7 +37,7 @@ private class Printf extends FormattingFunction, AliasFunction, NonThrowingFunct
3737
/**
3838
* The standard functions `fprintf`, `fwprintf` and their glib variants.
3939
*/
40-
private class Fprintf extends FormattingFunction, NonThrowingFunction {
40+
private class Fprintf extends FormattingFunction, NonCppThrowingFunction {
4141
Fprintf() {
4242
this instanceof TopLevelFunction and
4343
(
@@ -55,7 +55,7 @@ private class Fprintf extends FormattingFunction, NonThrowingFunction {
5555
/**
5656
* The standard function `sprintf` and its Microsoft and glib variants.
5757
*/
58-
private class Sprintf extends FormattingFunction, NonThrowingFunction {
58+
private class Sprintf extends FormattingFunction, NonCppThrowingFunction {
5959
Sprintf() {
6060
this instanceof TopLevelFunction and
6161
(
@@ -98,7 +98,9 @@ private class Sprintf extends FormattingFunction, NonThrowingFunction {
9898
/**
9999
* Implements `Snprintf`.
100100
*/
101-
private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction, NonThrowingFunction {
101+
private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction,
102+
NonCppThrowingFunction
103+
{
102104
SnprintfImpl() {
103105
this instanceof TopLevelFunction and
104106
(
@@ -205,7 +207,7 @@ private class StringCchPrintf extends FormattingFunction {
205207
/**
206208
* The standard function `syslog`.
207209
*/
208-
private class Syslog extends FormattingFunction, NonThrowingFunction {
210+
private class Syslog extends FormattingFunction, NonCppThrowingFunction {
209211
Syslog() {
210212
this instanceof TopLevelFunction and
211213
this.hasGlobalName("syslog") and

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import semmle.code.cpp.models.interfaces.NonThrowing
1515
* Does not include `strlcat`, which is covered by `StrlcatFunction`
1616
*/
1717
class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, SideEffectFunction,
18-
NonThrowingFunction
18+
NonCppThrowingFunction
1919
{
2020
StrcatFunction() {
2121
this.hasGlobalOrStdOrBslName([

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import semmle.code.cpp.models.interfaces.NonThrowing
1313
* The standard function `strcpy` and its wide, sized, and Microsoft variants.
1414
*/
1515
class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, SideEffectFunction,
16-
NonThrowingFunction
16+
NonCppThrowingFunction
1717
{
1818
StrcpyFunction() {
1919
this.hasGlobalOrStdOrBslName([
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import semmle.code.cpp.models.interfaces.Throwing
22

3-
class WindowsDriverFunction extends ThrowingFunction {
4-
WindowsDriverFunction() {
3+
class WindowsDriverExceptionAnnotation extends AlwaysSehThrowingFunction {
4+
WindowsDriverExceptionAnnotation() {
55
this.hasGlobalName(["RaiseException", "ExRaiseAccessViolation", "ExRaiseDatatypeMisalignment"])
66
}
7-
8-
final override predicate mayThrowException(boolean unconditional) { unconditional = true }
97
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
import semmle.code.cpp.Function
66
import semmle.code.cpp.models.Models
77

8+
/**
9+
* A function that is guaranteed to never throw a C++ exception
10+
*
11+
* The function may still raise a structured exception handling (SEH) exception.
12+
*/
13+
abstract class NonCppThrowingFunction extends Function { }
14+
815
/**
916
* A function that is guaranteed to never throw.
17+
*
18+
* DEPRECATED: use `NonCppThrowingFunction` instead.
1019
*/
11-
abstract class NonThrowingFunction extends Function { }
20+
deprecated class NonThrowingFunction = NonCppThrowingFunction;

0 commit comments

Comments
 (0)