]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
checkpatch.pl: warn also about strcat and sprintf usages
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 18 Jul 2024 11:01:00 +0000 (13:01 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 18 Jul 2024 11:03:45 +0000 (13:03 +0200)
strcpy, strncpy and sprintf aren't safe, as they don't check
buffer overflows. Change the checkpatch logic to warn about
such usages.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
scripts/checkpatch.pl

index e81e5097a6ba68db17446649ad1df3d2ae083f25..7ed2ec629edcb1e9cd8284ff14ee9734a49a8981 100755 (executable)
@@ -6675,10 +6675,10 @@ sub process {
 #                      }
 #              }
 
-# strcpy should be avoided
-               if ($line =~ /\bstrcpy\s*\(/) {
+# strcpy and strcat should be avoided
+               if ($line =~ /\b(strcpy|strcat|sprintf)\s*\(/) {
                        WARN("STRCPY",
-                            "Please avoid strcpy\n" . $herecurr);
+                            "Please avoid $1 as it doesn't check buffer size\n" . $herecurr);
                }
 
 # ethtool_sprintf uses that should likely be ethtool_puts