Skip to content

Commit 84c7f19

Browse files
Merge pull request #994 from geoffw0/msalloc
CPP: Add lots more allocation functions to Alloc.qll
2 parents 5c2804d + c637bc5 commit 84c7f19

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

change-notes/1.20/analysis-cpp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
| Suspicious pointer scaling (`cpp/suspicious-pointer-scaling`) | Fewer false positives | False positives involving types that are not uniquely named in the snapshot have been fixed. |
2525
| Call to memory access function may overflow buffer (`cpp/overflow-buffer`) | More correct results | Calls to `fread` are now examined by this query. |
2626
| Lossy function result cast (`cpp/lossy-function-result-cast`) | Fewer false positive results | The whitelist of rounding functions built into this query has been expanded. |
27+
| Memory is never freed (`cpp/memory-never-freed`) | More correct results | Support for more Microsoft-specific memory allocation/de-allocation functions has been added. |
28+
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More correct results | Support for more Microsoft-specific memory allocation/de-allocation functions has been added. |
2729
| Unused static variable (`cpp/unused-static-variable`) | Fewer false positive results | Variables with the attribute `unused` are now excluded from the query. |
2830
| Resource not released in destructor (`cpp/resource-not-released-in-destructor`) | Fewer false positive results | Fix false positives where a resource is released via a virtual method call, function pointer, or lambda. |
2931
| 'new[]' array freed with 'delete' (`cpp/new-array-delete-mismatch`) | More correct results | Data flow through global variables for this query has been improved. |

cpp/ql/src/semmle/code/cpp/commons/Alloc.qll

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,31 @@ predicate allocationFunction(Function f)
1515
name = "wcsdup" or
1616
name = "_strdup" or
1717
name = "_wcsdup" or
18-
name = "_mbsdup"
18+
name = "_mbsdup" or
19+
name = "ExAllocatePool" or
20+
name = "ExAllocatePoolWithTag" or
21+
name = "ExAllocatePoolWithTagPriority" or
22+
name = "ExAllocatePoolWithQuota" or
23+
name = "ExAllocatePoolWithQuotaTag" or
24+
name = "ExAllocateFromLookasideListEx" or
25+
name = "ExAllocateFromPagedLookasideList" or
26+
name = "ExAllocateFromNPagedLookasideList" or
27+
name = "ExAllocateTimer" or
28+
name = "IoAllocateMdl" or
29+
name = "IoAllocateWorkItem" or
30+
name = "IoAllocateErrorLogEntry" or
31+
name = "MmAllocateContiguousMemory" or
32+
name = "MmAllocateContiguousNodeMemory" or
33+
name = "MmAllocateContiguousMemorySpecifyCache" or
34+
name = "MmAllocateContiguousMemorySpecifyCacheNode" or
35+
name = "MmAllocateNonCachedMemory" or
36+
name = "MmAllocateMappingAddress" or
37+
name = "MmAllocatePagesForMdl" or
38+
name = "MmAllocatePagesForMdlEx" or
39+
name = "MmAllocateNodePagesForMdlEx" or
40+
name = "MmMapLockedPagesWithReservedMapping" or
41+
name = "MmMapLockedPages" or
42+
name = "MmMapLockedPagesSpecifyCache"
1943
)
2044
)
2145
}
@@ -42,7 +66,22 @@ predicate freeFunction(Function f, int argNum)
4266
f.hasQualifiedName(name) and
4367
(
4468
(name = "free" and argNum = 0) or
45-
(name = "realloc" and argNum = 0)
69+
(name = "realloc" and argNum = 0) or
70+
(name = "ExFreePoolWithTag" and argNum = 0) or
71+
(name = "ExFreeToLookasideListEx" and argNum = 1) or
72+
(name = "ExFreeToPagedLookasideList" and argNum = 1) or
73+
(name = "ExFreeToNPagedLookasideList" and argNum = 1) or
74+
(name = "ExDeleteTimer" and argNum = 0) or
75+
(name = "IoFreeMdl" and argNum = 0) or
76+
(name = "IoFreeWorkItem" and argNum = 0) or
77+
(name = "IoFreeErrorLogEntry" and argNum = 0) or
78+
(name = "MmFreeContiguousMemory" and argNum = 0) or
79+
(name = "MmFreeContiguousMemorySpecifyCache" and argNum = 0) or
80+
(name = "MmFreeNonCachedMemory" and argNum = 0) or
81+
(name = "MmFreeMappingAddress" and argNum = 0) or
82+
(name = "MmFreePagesFromMdl" and argNum = 0) or
83+
(name = "MmUnmapReservedMapping" and argNum = 0) or
84+
(name = "MmUnmapLockedPages" and argNum = 0)
4685
)
4786
)
4887
}

0 commit comments

Comments
 (0)