]> git.proxmox.com Git - mirror_frr.git/blob - tools/coccinelle/strncpy_truncation.cocci
Merge pull request #8593 from idryzhov/cmd-ambiguous
[mirror_frr.git] / tools / coccinelle / strncpy_truncation.cocci
1 /// Use strlcpy rather than strncpy(dest,..,sz) + dest[sz-1] = '\0'
2 ///
3 // Confidence: High
4 // Comments:
5 // Options: --no-includes --include-headers
6
7 virtual patch
8 virtual context
9 virtual report
10 virtual org
11
12 @r@
13 expression dest, src, sz;
14 position p;
15 @@
16
17 strncpy@p(dest, src, sz);
18 dest[sz - 1] = '\0';
19
20 @script:python depends on org@
21 p << r.p;
22 @@
23
24 cocci.print_main("strncpy followed by truncation can be strlcpy",p)
25
26 @script:python depends on report@
27 p << r.p;
28 @@
29
30 msg = "SUGGESTION: strncpy followed by truncation can be strlcpy"
31 coccilib.report.print_report(p[0],msg)
32
33 @ok depends on patch@
34 expression r.dest, r.src, r.sz;
35 position r.p;
36 @@
37
38 -strncpy@p(
39 +strlcpy(
40 dest, src, sz);
41 -dest[sz - 1] = '\0';