@@ -16,6 +16,7 @@ private class StrdupFunction extends AllocationFunction, ArrayFunction, DataFlow
16
16
hasGlobalName ( [
17
17
// --- C library allocation
18
18
"strdup" , // strdup(str)
19
+ "strdupa" , // strdupa(str) - returns stack allocated buffer
19
20
"wcsdup" , // wcsdup(str)
20
21
"_strdup" , // _strdup(str)
21
22
"_wcsdup" , // _wcsdup(str)
@@ -31,18 +32,20 @@ private class StrdupFunction extends AllocationFunction, ArrayFunction, DataFlow
31
32
input .isParameterDeref ( 0 ) and
32
33
output .isReturnValueDeref ( )
33
34
}
35
+
36
+ override predicate requiresDealloc ( ) { not hasGlobalName ( "strdupa" ) }
34
37
}
35
38
36
39
/**
37
40
* A `strndup` style allocation function.
38
41
*/
39
42
private class StrndupFunction extends AllocationFunction , ArrayFunction , DataFlowFunction {
40
43
StrndupFunction ( ) {
41
- exists ( string name |
42
- hasGlobalName ( name ) and
43
- // --- C library allocation
44
- name = "strndup " // strndup (str, maxlen)
45
- )
44
+ hasGlobalName ( [
45
+ // -- C library allocation
46
+ "strndup" , // strndup(str, maxlen)
47
+ "strndupa " // strndupa (str, maxlen) -- returns stack allocated buffer
48
+ ] )
46
49
}
47
50
48
51
override predicate hasArrayInput ( int bufParam ) { bufParam = 0 }
@@ -56,4 +59,6 @@ private class StrndupFunction extends AllocationFunction, ArrayFunction, DataFlo
56
59
) and
57
60
output .isReturnValueDeref ( )
58
61
}
62
+
63
+ override predicate requiresDealloc ( ) { not hasGlobalName ( "strndupa" ) }
59
64
}
0 commit comments