From: Eric Leblond Date: Sat, 30 Nov 2019 16:20:44 +0000 (+0100) Subject: qa/coccinelle: fix false positive in setter getter X-Git-Tag: suricata-5.0.1~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ded7f1170f7ab1a5b6f0fa58c04cb2949ec525f;p=thirdparty%2Fsuricata.git 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. --- diff --git a/qa/coccinelle/struct-flags.py b/qa/coccinelle/struct-flags.py index 81fa09aa84..93377bd9bb 100755 --- a/qa/coccinelle/struct-flags.py +++ b/qa/coccinelle/struct-flags.py @@ -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; @@ diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 03f23dd1c7..b7de5c0f40 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -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();