mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 13:21:29 +02: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…
x
Reference in New Issue
Block a user