haproxy/dev/coccinelle/unchecked-strdup.cocci
Ilia Shipitsin 661e1db826 DEV: coccinelle: add a test to detect unchecked strdup()
The coccinelle test "unchecked-strdup.cocci" detects various cases of
unchecked strdup().
2024-08-06 08:21:49 +02:00

35 lines
413 B
Plaintext

// 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;