mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-15 21:59:41 -04: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
1 changed files with 34 additions and 0 deletions
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 a new issue