qa/coccinelle: fix false positive in setter getter

Coccinelle test was doing a false positive on the function
AppLayerParserStateSetFlag and AppLayerParserStateIssetFlag.
To address that, this patch adds a new coccinelle markup:

 /* coccinelle: AppLayerParserStateSetFlag():2,2:APP_LAYER_PARSER_ */

It indicates that AppLayerParserStateSetFlag is a setter and getter
and that the checks should be disabled inside the function.

Currently this markup is only used for that but following patch will
add some checks on option value.
pull/4420/head
Eric Leblond 6 years ago committed by Victor Julien
parent f745f0655b
commit 3ded7f1170

@ -9,10 +9,17 @@ class Structure:
def __init__(self, string):
(self.struct, self.flags, self.values) = string.split(":")
class SetterGetter:
def __init__(self, string):
(function, params, self.value) = string.split(":")
self.function = function.strip("()")
self.params = [int(a) for a in params.split(",")]
cmd = "grep -h coccinelle ../../src/*[ch] | sed -e 's/.*coccinelle: \(.*\) \*\//\1/'"
struct_list = []
setter_getter_list = []
dirList = listdir(SRC_DIR)
for fname in dirList:
@ -20,12 +27,21 @@ for fname in dirList:
for line in open(SRC_DIR + fname):
if "coccinelle:" in line:
m = re.search("coccinelle: (.*) \*\/", line)
struct = Structure(m.group(1))
struct_list.append(struct)
if "()" not in m.group(1):
struct = Structure(m.group(1))
struct_list.append(struct)
else:
function = SetterGetter(m.group(1))
setter_getter_list.append(function)
header = "@flags@"
body = []
# Handle setter and getter
setter_getter = [x.function for x in setter_getter_list]
if len(setter_getter):
header += "\nidentifier NotSetterGetter !~ \"^(%s)$\";" % ("|".join(setter_getter))
i = 0
for struct in struct_list:
header += """
@ -46,9 +62,19 @@ print(header)
print("position p1;")
print("@@")
print("")
print("""
NotSetterGetter(...)
{
<...
""")
print("")
print("(" + "|".join(body) + ")")
print("")
print("""@script:python@
print("""
...>
}
@script:python@
p1 << flags.p1;
@@

@ -1575,6 +1575,7 @@ void AppLayerParserRegisterProtocolParsers(void)
}
/* coccinelle: AppLayerParserStateSetFlag():2,2:APP_LAYER_PARSER_ */
void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint8_t flag)
{
SCEnter();
@ -1582,6 +1583,7 @@ void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint8_t flag)
SCReturn;
}
/* coccinelle: AppLayerParserStateIssetFlag():2,2:APP_LAYER_PARSER_ */
int AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint8_t flag)
{
SCEnter();

Loading…
Cancel
Save