mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-18 01:14:38 +00:00
DEV: coccinelle: add a test to detect unchecked strdup()
The coccinelle test "unchecked-strdup.cocci" detects various cases of unchecked strdup().
This commit is contained in:
parent
eb1a097a66
commit
661e1db826
34
dev/coccinelle/unchecked-strdup.cocci
Normal file
34
dev/coccinelle/unchecked-strdup.cocci
Normal file
@ -0,0 +1,34 @@
|
||||
// find calls to strdup
|
||||
@call@
|
||||
expression ptr;
|
||||
position p;
|
||||
@@
|
||||
|
||||
ptr@p = strdup(...);
|
||||
|
||||
// find ok calls to strdup
|
||||
@ok@
|
||||
expression ptr;
|
||||
position call.p;
|
||||
@@
|
||||
|
||||
ptr@p = strdup(...);
|
||||
... when != ptr
|
||||
(
|
||||
(ptr == NULL || ...)
|
||||
|
|
||||
(ptr == 0 || ...)
|
||||
|
|
||||
(ptr != NULL || ...)
|
||||
|
|
||||
(ptr != 0 || ...)
|
||||
)
|
||||
|
||||
// fix bad calls to strdup
|
||||
@depends on !ok@
|
||||
expression ptr;
|
||||
position call.p;
|
||||
@@
|
||||
|
||||
ptr@p = strdup(...);
|
||||
+ if (ptr == NULL) return;
|
Loading…
Reference in New Issue
Block a user