Excluding file paths
A message that is not in the archive (sent off-list or not yet received): 202402191257.843BC9BC@keescook
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 ofarch/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/orsamples/.Thanks!
-Kees
--
Kees Cook
A message that is not in the archive (sent off-list or not yet received): 202402191324.915AFFD6C2@keescook
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 ofarch/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