Skip to content

Commit 9b5be99

Browse files
committed
CPP: Split Strdup model into it's own class and file.
1 parent ce389ca commit 9b5be99

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

cpp/ql/src/semmle/code/cpp/models/Models.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ private import implementations.Printf
99
private import implementations.Pure
1010
private import implementations.Strcat
1111
private import implementations.Strcpy
12+
private import implementations.Strdup
1213
private import implementations.Strftime
1314
private import implementations.Swap

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,32 +173,14 @@ class ReallocAllocationFunction extends AllocationFunction {
173173
}
174174

175175
/**
176-
* An allocation function (such as `strdup`) that has no explicit argument for
176+
* A miscellaneous allocation function that has no explicit argument for
177177
* the size of the allocation.
178178
*/
179-
class StrdupAllocationFunction extends AllocationFunction {
180-
StrdupAllocationFunction() {
179+
class SizelessAllocationFunction extends AllocationFunction {
180+
SizelessAllocationFunction() {
181181
exists(string name |
182-
hasGlobalOrStdName(name) and
183-
(
184-
// strdup(str)
185-
name = "strdup"
186-
or
187-
// wcsdup(str)
188-
name = "wcsdup"
189-
)
190-
or
191182
hasGlobalName(name) and
192183
(
193-
// _strdup(str)
194-
name = "_strdup"
195-
or
196-
// _wcsdup(str)
197-
name = "_wcsdup"
198-
or
199-
// _mbsdup(str)
200-
name = "_mbsdup"
201-
or
202184
// ExAllocateFromLookasideListEx(list)
203185
name = "ExAllocateFromLookasideListEx"
204186
or
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import semmle.code.cpp.models.interfaces.Allocation
2+
3+
/**
4+
* A `strdup` style allocation function.
5+
*/
6+
class StrdupFunction extends AllocationFunction {
7+
StrdupFunction() {
8+
exists(string name |
9+
hasGlobalOrStdName(name) and
10+
(
11+
// strdup(str)
12+
name = "strdup"
13+
or
14+
// wcsdup(str)
15+
name = "wcsdup"
16+
)
17+
or
18+
hasGlobalName(name) and
19+
(
20+
// _strdup(str)
21+
name = "_strdup"
22+
or
23+
// _wcsdup(str)
24+
name = "_wcsdup"
25+
or
26+
// _mbsdup(str)
27+
name = "_mbsdup"
28+
)
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)