From: Paul Chaignon <paul@cilium.io>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] Whitelist function in rule
Date: Tue, 2 Jun 2020 14:45:23 +0200 [thread overview]
Message-ID: <20200602124522.GA2774@Mem> (raw)
In-Reply-To: <alpine.DEB.2.21.2006021214430.4634@hadrien>
On Tue, Jun 02, 2020 at 12:19:50PM +0200, Julia Lawall wrote:
>
>
> On Tue, 2 Jun 2020, Paul Chaignon wrote:
>
> > Hi all,
> >
> > I'm trying to find calls to ep_tail_call() that are *not* followed by
> > 'return DROP_MISSED_TAIL_CALL'. That works fine (rule1 below), but I then
> > want to whitelist one specific function, send_drop_notify().
> >
> > I couldn't find a way to do that from the first rule, so I whitelisted
> > send_drop_notify() with a second rule (rule2 below). That seems rather
> > cumbersome and I'm wondering if there's maybe a simpler approach?
> >
> > @rule1@
> > position p1;
>
> In coccinelle/tests/python_poscon.cocci you have an example of how to
> attach python code to a metavariable:
>
> @initialize:python@
> @@
>
> def past_line_4(p, other):
> return int(p[0].line) > 4
>
> @r@
> expression e;
> @@
>
> f(e)
>
> @@
> position p : script:python(r.e) { past_line_4(p, e) };
> expression r.e;
> @@
>
> g(
> -e@p
> +27
> )
>
> In your case, I think that in the python code you should be able to access
> p1[0].current_element. You can check that that is different than the
> name of the function that you want to ignore. There are some limitations
> on what can be put in the {} in such a metavariable declaration, so if you
> have problems you can make a function, as shown in the example. That code
> should return true if you want the match to take place and false
> otherwise.
Thanks! That worked great!
And the Python filtering looks super useful; I'm likely going to be
using that a lot :-)
Paul
>
> julia
>
>
>
> > @@
> >
> > (
> > ep_tail_call(...);
> > ... when forall
> > return DROP_MISSED_TAIL_CALL;
> > |
> > ep_tail_call@p1(...);
> > )
> >
> > @rule2@
> > position p2, rule1.p1;
> > identifier fn != send_drop_notify;
> > @@
> >
> > fn(...) {
> > <+...
> > ep_tail_call@p1@p2(...);
> > ...+>
> > }
> >
> > When I tried using rule1 as the body of the function in rule2, it just
> > didn't match anything anymore.
> >
> > Thanks,
> > Paul
> > _______________________________________________
> > Cocci mailing list
> > Cocci@systeme.lip6.fr
> > https://systeme.lip6.fr/mailman/listinfo/cocci
> >
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-06-02 12:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 9:28 [Cocci] Whitelist function in rule Paul Chaignon
2020-06-02 10:19 ` Julia Lawall
2020-06-02 12:45 ` Paul Chaignon [this message]
2020-06-02 12:55 ` Julia Lawall
2020-06-02 18:57 ` Paul Chaignon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200602124522.GA2774@Mem \
--to=paul@cilium.io \
--cc=cocci@systeme.lip6.fr \
--cc=julia.lawall@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.