Skip to content

Commit cc43bb1

Browse files
committed
Merge branch 'brodes/seh_flow_phase1_throwing_models' into brodes/seh_flow_phase2_splitting_seh_edges
2 parents 007dd83 + e6641e7 commit cc43bb1

File tree

12 files changed

+41
-100
lines changed

12 files changed

+41
-100
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
category: deprecated
33
---
4-
* The `NonThrowing` class (`semmle.code.cpp.models.interfaces.NonThrowing`) has been deprecated. Please use the `NonThrowing` class from `semmle.code.cpp.models.interfaces.Throwing` instead.
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import semmle.code.cpp.models.interfaces.DataFlow
99
import semmle.code.cpp.models.interfaces.Alias
1010
import semmle.code.cpp.models.interfaces.SideEffect
1111
import semmle.code.cpp.models.interfaces.Taint
12-
import semmle.code.cpp.models.interfaces.Throwing
12+
import semmle.code.cpp.models.interfaces.NonThrowing
1313

1414
/**
1515
* The standard functions `memcpy`, `memmove` and `bcopy`; and the gcc variant
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)
@@ -106,8 +106,6 @@ private class MemcpyFunction extends ArrayFunction, DataFlowFunction, SideEffect
106106
not this.hasGlobalName(["bcopy", mempcpy(), "memccpy"]) and
107107
index = this.getParamDest()
108108
}
109-
110-
override TCxxException getExceptionType() { any() }
111109
}
112110

113111
private string mempcpy() { result = ["mempcpy", "wmempcpy"] }

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import semmle.code.cpp.models.interfaces.ArrayFunction
88
import semmle.code.cpp.models.interfaces.DataFlow
99
import semmle.code.cpp.models.interfaces.Alias
1010
import semmle.code.cpp.models.interfaces.SideEffect
11-
import semmle.code.cpp.models.interfaces.Throwing
11+
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")
@@ -74,8 +74,6 @@ private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, Alias
7474
i = 0 and
7575
if this.hasGlobalName(bzero()) then result = 1 else result = 2
7676
}
77-
78-
override TCxxException getExceptionType() { any() }
7977
}
8078

8179
private string bzero() { result = ["bzero", "explicit_bzero"] }
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import semmle.code.cpp.models.interfaces.Throwing
1+
import semmle.code.cpp.models.interfaces.NonThrowing
22

33
/**
44
* A function that is annotated with a `noexcept` specifier (or the equivalent
55
* `throw()` specifier) guaranteeing that the function can not throw exceptions.
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() }
11-
12-
override TCxxException getExceptionType() { any() }
1311
}

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +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.Throwing
11+
import semmle.code.cpp.models.interfaces.NonThrowing
1212

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
(
@@ -32,14 +32,12 @@ private class Printf extends FormattingFunction, AliasFunction, NonThrowingFunct
3232
override predicate parameterEscapesOnlyViaReturn(int n) { none() }
3333

3434
override predicate parameterIsAlwaysReturned(int n) { none() }
35-
36-
override TCxxException getExceptionType() { any() }
3735
}
3836

3937
/**
4038
* The standard functions `fprintf`, `fwprintf` and their glib variants.
4139
*/
42-
private class Fprintf extends FormattingFunction, NonThrowingFunction {
40+
private class Fprintf extends FormattingFunction, NonCppThrowingFunction {
4341
Fprintf() {
4442
this instanceof TopLevelFunction and
4543
(
@@ -52,14 +50,12 @@ private class Fprintf extends FormattingFunction, NonThrowingFunction {
5250
override int getFormatParameterIndex() { result = 1 }
5351

5452
override int getOutputParameterIndex(boolean isStream) { result = 0 and isStream = true }
55-
56-
override TCxxException getExceptionType() { any() }
5753
}
5854

5955
/**
6056
* The standard function `sprintf` and its Microsoft and glib variants.
6157
*/
62-
private class Sprintf extends FormattingFunction, NonThrowingFunction {
58+
private class Sprintf extends FormattingFunction, NonCppThrowingFunction {
6359
Sprintf() {
6460
this instanceof TopLevelFunction and
6561
(
@@ -97,14 +93,14 @@ private class Sprintf extends FormattingFunction, NonThrowingFunction {
9793
then result = 4
9894
else result = super.getFirstFormatArgumentIndex()
9995
}
100-
101-
override TCxxException getExceptionType() { any() }
10296
}
10397

10498
/**
10599
* Implements `Snprintf`.
106100
*/
107-
private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction, NonThrowingFunction {
101+
private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction,
102+
NonCppThrowingFunction
103+
{
108104
SnprintfImpl() {
109105
this instanceof TopLevelFunction and
110106
(
@@ -171,8 +167,6 @@ private class SnprintfImpl extends Snprintf, AliasFunction, SideEffectFunction,
171167
// We don't know how many parameters are passed to the function since it's varargs, but they also have read side effects.
172168
i = this.getFormatParameterIndex() and buffer = true
173169
}
174-
175-
override TCxxException getExceptionType() { any() }
176170
}
177171

178172
/**
@@ -213,7 +207,7 @@ private class StringCchPrintf extends FormattingFunction {
213207
/**
214208
* The standard function `syslog`.
215209
*/
216-
private class Syslog extends FormattingFunction, NonThrowingFunction {
210+
private class Syslog extends FormattingFunction, NonCppThrowingFunction {
217211
Syslog() {
218212
this instanceof TopLevelFunction and
219213
this.hasGlobalName("syslog") and
@@ -223,6 +217,4 @@ private class Syslog extends FormattingFunction, NonThrowingFunction {
223217
override int getFormatParameterIndex() { result = 1 }
224218

225219
override predicate isOutputGlobal() { any() }
226-
227-
override TCxxException getExceptionType() { any() }
228220
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ 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.Throwing
10+
import semmle.code.cpp.models.interfaces.NonThrowing
1111

1212
/**
1313
* The standard function `strcat` and its wide, sized, and Microsoft variants.
1414
*
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([
@@ -94,8 +94,6 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
9494
(i = 0 or i = 1) and
9595
buffer = true
9696
}
97-
98-
override TCxxException getExceptionType() { any() }
9997
}
10098

10199
/**

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ 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.Throwing
10+
import semmle.code.cpp.models.interfaces.NonThrowing
1111

1212
/**
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([
@@ -145,6 +145,4 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
145145
i = this.getParamDest() and
146146
result = this.getParamSize()
147147
}
148-
149-
override TCxxException getExceptionType() { any() }
150148
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import semmle.code.cpp.models.interfaces.Throwing
22

3-
class WindowsDriverExceptionAnnotation extends ThrowingFunction {
3+
class WindowsDriverExceptionAnnotation extends AlwaysSehThrowingFunction {
44
WindowsDriverExceptionAnnotation() {
55
this.hasGlobalName(["RaiseException", "ExRaiseAccessViolation", "ExRaiseDatatypeMisalignment"])
66
}
7-
8-
override predicate mayThrowException(boolean unconditional) { unconditional = true }
9-
10-
override TSehException getExceptionType() { any() }
117
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +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.
1017
*
11-
* DEPRECATED: use `NonThrowingFunction` in `semmle.code.cpp.models.Models.Interfaces.Throwing` instead.
18+
* DEPRECATED: use `NonCppThrowingFunction` instead.
1219
*/
13-
abstract deprecated class NonThrowingFunction extends Function { }
20+
deprecated class NonThrowingFunction = NonCppThrowingFunction;

0 commit comments

Comments
 (0)