Skip to content

Commit bcd36b1

Browse files
committed
C++: Recognize glib allocations and deallocations.
1 parent c190dd2 commit bcd36b1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ private class MallocAllocationFunction extends AllocationFunction {
3636
"CRYPTO_malloc", // CRYPTO_malloc(size_t num, const char *file, int line)
3737
"CRYPTO_zalloc", // CRYPTO_zalloc(size_t num, const char *file, int line)
3838
"CRYPTO_secure_malloc", // CRYPTO_secure_malloc(size_t num, const char *file, int line)
39-
"CRYPTO_secure_zalloc" // CRYPTO_secure_zalloc(size_t num, const char *file, int line)
39+
"CRYPTO_secure_zalloc", // CRYPTO_secure_zalloc(size_t num, const char *file, int line)
40+
"g_malloc", // g_malloc (n_bytes);
41+
"g_try_malloc" // g_try_malloc(n_bytes);
4042
]) and
4143
sizeArg = 0
4244
or
@@ -139,7 +141,9 @@ private class ReallocAllocationFunction extends AllocationFunction, TaintFunctio
139141
// --- Windows COM allocation
140142
"CoTaskMemRealloc", // CoTaskMemRealloc(ptr, size)
141143
// --- OpenSSL memory allocation
142-
"CRYPTO_realloc" // CRYPTO_realloc(void *addr, size_t num, const char *file, int line)
144+
"CRYPTO_realloc", // CRYPTO_realloc(void *addr, size_t num, const char *file, int line)
145+
"g_realloc", // g_realloc(mem, n_bytes);
146+
"g_try_realloc" // g_try_realloc(mem, n_bytes);
143147
]) and
144148
sizeArg = 1 and
145149
reallocArg = 0

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ private class StandardDeallocationFunction extends DeallocationFunction {
2020
freedArg = 0
2121
or
2222
this.hasGlobalName([
23-
// --- OpenSSL memory allocation
24-
"CRYPTO_free", "CRYPTO_secure_free"
23+
// --- OpenSSL memory deallocation
24+
"CRYPTO_free", "CRYPTO_secure_free",
25+
// --- glib memory deallocation
26+
"g_free"
2527
]) and
2628
freedArg = 0
2729
or

0 commit comments

Comments
 (0)