]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
coccinelle: fix malloc test
authorEric Leblond <eric@regit.org>
Mon, 9 Dec 2013 16:02:55 +0000 (17:02 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 10 Dec 2013 10:35:09 +0000 (11:35 +0100)
We can have more than an identifier to be assigned the result of
a malloc function.

qa/coccinelle/malloc-error-check.cocci

index 67769a042a8eac4932c649feb631550a61c6252d..b245189a23b4a04faf3558e08103cc7ad099f119 100644 (file)
@@ -1,23 +1,36 @@
 @malloced@
-identifier x;
+expression x;
 position p1;
 identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
 @@
 
 x@p1 = func(...)
 
-
 @inlinetested@
-identifier x;
-position p1;
+expression x, E;
 statement S;
+position malloced.p1;
 identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
 @@
 
+(
 if ((x@p1 = func(...)) == NULL) S
+|
+if (E && (x@p1 = func(...)) == NULL) S
+)
+
+@realloc exists@
+position malloced.p1;
+expression x, E1;
+identifier func =~ "(SCMalloc|SCCalloc|SCMallocAligned)";
+@@
+
+x@p1 = func(...)
+... when != x
+x = SCRealloc(x, E1)
 
-@istested@
-identifier x;
+@istested depends on !realloc exists@
+expression x, E1;
 position malloced.p1;
 statement S1, S2;
 identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
@@ -28,19 +41,23 @@ x@p1 = func(...)
 (
 if (unlikely(x == NULL)) S1
 |
+if (unlikely(x == NULL)) S1 else S2
+|
 if (likely(x != NULL)) S1
 |
 if (x == NULL) S1
 |
 if (x != NULL) S1 else S2
 |
+if (x && E1) S1
+|
 BUG_ON(x == NULL)
 )
 
-@script:python depends on malloced && !istested && !inlinetested @
+
+@script:python depends on !realloc && !istested && !inlinetested@
 p1 << malloced.p1;
 @@
-
 print "Structure malloced at %s:%s but error is not checked." % (p1[0].file, p1[0].line)
 import sys
 sys.exit(1)