From 238cad77e2af8e19fe27f4650992556e7d20e1b3 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sat, 5 Nov 2011 12:02:19 +0100 Subject: [PATCH] coccinelle: test for invalid size_t printing. --- qa/coccinelle/size_t.cocci | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 qa/coccinelle/size_t.cocci diff --git a/qa/coccinelle/size_t.cocci b/qa/coccinelle/size_t.cocci new file mode 100644 index 0000000000..6363692b7b --- /dev/null +++ b/qa/coccinelle/size_t.cocci @@ -0,0 +1,44 @@ +@sizet@ +size_t p; +identifier func ~= "^\(sprintf\|printf\|SCLog.*\)$"; +identifier funcn ~= "^.*nprintf$"; +position p1; +typedef uint16_t; +typedef uint32_t; +typedef uint64_t; +expression E1, E2; +@@ + +( +func(..., p, ...)@p1; +| +func(..., (int) p, ...)@p1; +| +func(..., (unsigned int) p, ...)@p1; +| +func(..., (uint16_t) p, ...)@p1; +| +func(..., (uint32_t) p, ...)@p1; +| +func(..., (uint64_t) p, ...)@p1; +| +funcn(E1, E2,..., p, ...)@p1; +| +funcn(E1, E2,..., (int) p, ...)@p1; +| +funcn(E1, E2,..., (unsigned int) p, ...)@p1; +| +funcn(E1, E2,..., (uint16_t) p, ...)@p1; +| +funcn(E1, E2,..., (uint32_t) p, ...)@p1; +| +funcn(E1, E2,..., (uint64_t) p, ...)@p1; +) + +@ script:python @ +p1 << sizet.p1; +@@ + +print "Invalid printf with size_t (not casted to uintmax_t) at %s:%s" % (p1[0].file, p1[0].line) +import sys +sys.exit(1)