Patchwork [2,of,2] check-code: prevent use of strcpy

login
register
mail settings
Submitter Augie Fackler
Date March 20, 2016, 12:21 a.m.
Message ID <88555c2f8946f95ee142.1458433303@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/13969/
State Accepted
Headers show

Comments

Augie Fackler - March 20, 2016, 12:21 a.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1458433118 14400
#      Sat Mar 19 20:18:38 2016 -0400
# Node ID 88555c2f8946f95ee1427d4e161a0f10b3f41f52
# Parent  e09de2f7fe03ba5cb0ba387dee866ffae00bb922
check-code: prevent use of strcpy
Pierre-Yves David - March 20, 2016, 12:43 a.m.
On 03/19/2016 05:21 PM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1458433118 14400
> #      Sat Mar 19 20:18:38 2016 -0400
> # Node ID 88555c2f8946f95ee1427d4e161a0f10b3f41f52
> # Parent  e09de2f7fe03ba5cb0ba387dee866ffae00bb922
> check-code: prevent use of strcpy

Pushed to the clowncopter, thanks.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -359,6 +359,7 @@  cpats = [
     (r'^#\s+\w', "use #foo, not # foo"),
     (r'[^\n]\Z', "no trailing newline"),
     (r'^\s*#import\b', "use only #include in standard C code"),
+    (r'strcpy\(', "don't use strcpy, use strlcpy or memcpy"),
   ],
   # warnings
   []
diff --git a/tests/test-contrib-check-code.t b/tests/test-contrib-check-code.t
--- a/tests/test-contrib-check-code.t
+++ b/tests/test-contrib-check-code.t
@@ -69,6 +69,22 @@ 
    dict() is different in Py2 and 3 and is slower than {}
   [1]
 
+  $ cat > foo.c <<EOF
+  > void narf() {
+  > 	strcpy(foo, bar);
+  > 	// strcpy_s is okay, but this comment is not
+  > 	strcpy_s(foo, bar);
+  > }
+  > EOF
+  $ "$check_code" ./foo.c
+  ./foo.c:2:
+   > 	strcpy(foo, bar);
+   don't use strcpy, use strlcpy or memcpy
+  ./foo.c:3:
+   > 	// strcpy_s is okay, but this comment is not
+   don't use //-style comments
+  [1]
+
   $ cat > is-op.py <<EOF
   > # is-operator comparing number or string literal
   > x = None