cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* Re: [cocci] Excluding file paths
       [not found] <202402191257.843BC9BC@keescook>
@ 2024-02-19 21:12 ` Julia Lawall
       [not found]   ` <202402191324.915AFFD6C2@keescook>
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2024-02-19 21:12 UTC (permalink / raw)
  To: Kees Cook; +Cc: cocci, Nicolas Palix



On Mon, 19 Feb 2024, Kees Cook wrote:

> Hi!
>
> I keep running into this, and figured I should just ask: how do I
> exclude certain directories (or files) when using "--dir"? For example,
> we've been working on removing the ambiguous/fragile C string APIs in
> the kernel and replacing them with alternatives, but we can't do this
> for userspace programs, since the alternatives only exist in the kernel
> code base itself. Mainly, this is about excluding tools/ but there are
> also parts of arch/um/ that are built against userspace libraries.
>
> I tried using "--ignore" but it doesn't seem to work. What's the right
> solution here? For example, this trivial replacement:

You put the constraint in the initial @@ of the semantic patch.  Try

depends on !file in tools && !file in samples

Maybe parentheses would b needed, eg !(files in tools)

julia



>
>
> @@
> @@
>
> -snprintf
> +scnprintf
>  (...);
>
>
> I don't want this to touch anything in tools/ or samples/.
>
> Thanks!
>
> -Kees
>
> --
> Kees Cook
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [cocci] Excluding file paths
       [not found]   ` <202402191324.915AFFD6C2@keescook>
@ 2024-02-19 21:31     ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2024-02-19 21:31 UTC (permalink / raw)
  To: Kees Cook; +Cc: cocci, Nicolas Palix



On Mon, 19 Feb 2024, Kees Cook wrote:

> On Mon, Feb 19, 2024 at 10:12:10PM +0100, Julia Lawall wrote:
> >
> >
> > On Mon, 19 Feb 2024, Kees Cook wrote:
> >
> > > Hi!
> > >
> > > I keep running into this, and figured I should just ask: how do I
> > > exclude certain directories (or files) when using "--dir"? For example,
> > > we've been working on removing the ambiguous/fragile C string APIs in
> > > the kernel and replacing them with alternatives, but we can't do this
> > > for userspace programs, since the alternatives only exist in the kernel
> > > code base itself. Mainly, this is about excluding tools/ but there are
> > > also parts of arch/um/ that are built against userspace libraries.
> > >
> > > I tried using "--ignore" but it doesn't seem to work. What's the right
> > > solution here? For example, this trivial replacement:
> >
> > You put the constraint in the initial @@ of the semantic patch.  Try
> >
> > depends on !file in tools && !file in samples
> >
> > Maybe parentheses would b needed, eg !(files in tools)
>
> Thanks! Yes, this works:
>
>
> @scnprintf depends on !(file in "tools") && !(file in "samples")@
> @@
>
> -snprintf
> +scnprintf
>  (...);
>
>
> Now that I know the syntax, I found the part in the docs that
> references "file in":
>
>   The declaration file in checks that the code being processed comes from
>   the mentioned file, or from a subdirectory of the directory to which
>   Coccinelle was applied. In the latter case, the string is matched
>   against the complete pathname. A trailing / is added to the specified
>   subdirectory name, to ensure that a complete subdirectory name is
>   matched.
>
> https://coccinelle.gitlabpages.inria.fr/website/docs/main_grammar.html

Nice that it's useful :)

julia

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-19 21:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <202402191257.843BC9BC@keescook>
2024-02-19 21:12 ` [cocci] Excluding file paths Julia Lawall
     [not found]   ` <202402191324.915AFFD6C2@keescook>
2024-02-19 21:31     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).