Skip to contentSkip to conversation

Excluding file paths

cocci Julia Lawall 1 participant 2 messages Feb 19, 2024 2 messages not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 10 lines · Kees Cook

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.

Quoted 2 lines

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

Quoted 19 lines

@@
@@

(quoted diff) +1 -1
-snprintf
+scnprintf
 (...);

I don't want this to touch anything in tools/ or samples/.

Thanks!

-Kees

--
Kees Cook

#3 lore raw
In reply to a message not in the archive
Quoted 38 lines · Kees Cook
Quoted 14 lines · Julia Lawall
Quoted 10 lines · Kees Cook

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.

Quoted 8 lines
Quoted 2 lines

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")@ @@

(quoted diff) +1 -1
-snprintf
+scnprintf
 (...);

Now that I know the syntax, I found the part in the docs that references "file in":

Quoted 8 lines

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