Modified: trunk/Tools/ChangeLog (216016 => 216017)
--- trunk/Tools/ChangeLog 2017-05-01 17:06:16 UTC (rev 216016)
+++ trunk/Tools/ChangeLog 2017-05-01 17:06:40 UTC (rev 216017)
@@ -1,3 +1,21 @@
+2017-05-01 David Kilzer <[email protected]>
+
+ check-webkit-style: Enable sprintf(), strcat(), strcpy() and printf() format checks
+ <https://webkit.org/b/171494>
+
+ Reviewed by Brent Fulgham.
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (check_language): Change categories for certain checkers from
+ 'runtime/printf' to 'security/printf' so they are no longer
+ filtered.
+ (CppChecker.categories): Add 'security/printf'.
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+ (CppStyleTest.test_insecure_string_operations): Add new test for
+ sprintf(), strcat() and strcpy().
+ (CppStyleTest.test_format_strings): Update test results for new
+ 'security/printf' category use.
+
2017-05-01 Joanmarie Diggs <[email protected]>
AX: [GTK] Add support to query for aria-current
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (216016 => 216017)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2017-05-01 17:06:16 UTC (rev 216016)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2017-05-01 17:06:40 UTC (rev 216017)
@@ -3180,12 +3180,12 @@
# Check if some verboten C functions are being used.
if search(r'\bsprintf\b', line):
- error(line_number, 'runtime/printf', 5,
+ error(line_number, 'security/printf', 5,
'Never use sprintf. Use snprintf instead.')
matched = search(r'\b(strcpy|strcat)\b', line)
if matched:
- error(line_number, 'runtime/printf', 4,
- 'Almost always, snprintf is better than %s' % matched.group(1))
+ error(line_number, 'security/printf', 4,
+ 'Almost always, snprintf is better than %s.' % matched.group(1))
if search(r'\bsscanf\b', line):
error(line_number, 'runtime/printf', 1,
@@ -3202,7 +3202,7 @@
# Not perfect but it can catch printf(foo.c_str()) and printf(foo->c_str())
matched = re.search(r'\b((?:string)?printf)\s*\(([\w.\->()]+)\)', line, re.I)
if matched:
- error(line_number, 'runtime/printf', 4,
+ error(line_number, 'security/printf', 4,
'Potential format string bug. Do %s("%%s", %s) instead.'
% (matched.group(1), matched.group(2)))
@@ -3926,6 +3926,7 @@
'runtime/unsigned',
'runtime/virtual',
'runtime/wtf_move',
+ 'security/printf',
'whitespace/blank_line',
'whitespace/braces',
'whitespace/brackets',
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (216016 => 216017)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2017-05-01 17:06:16 UTC (rev 216016)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2017-05-01 17:06:40 UTC (rev 216017)
@@ -1528,6 +1528,22 @@
' for improved thread safety.'
' [runtime/threadsafe_fn] [2]')
+ # Test for insecure string functions like strcpy()/strcat().
+ def test_insecure_string_operations(self):
+ self.assert_lint(
+ 'sprintf(destination, "%s", arg)',
+ 'Never use sprintf. Use snprintf instead.'
+ ' [security/printf] [5]')
+ self.assert_lint(
+ 'strcat(destination, append)',
+ 'Almost always, snprintf is better than strcat.'
+ ' [security/printf] [4]')
+ self.assert_lint(
+ 'strcpy(destination, source)',
+ 'Almost always, snprintf is better than strcpy.'
+ ' [security/printf] [4]')
+ self.assert_lint('strstr(haystack, "needle")', '')
+
# Test potential format string bugs like printf(foo).
def test_format_strings(self):
self.assert_lint('printf("foo")', '')
@@ -1536,22 +1552,22 @@
self.assert_lint(
'printf(foo)',
'Potential format string bug. Do printf("%s", foo) instead.'
- ' [runtime/printf] [4]')
+ ' [security/printf] [4]')
self.assert_lint(
'printf(foo.c_str())',
'Potential format string bug. '
'Do printf("%s", foo.c_str()) instead.'
- ' [runtime/printf] [4]')
+ ' [security/printf] [4]')
self.assert_lint(
'printf(foo->c_str())',
'Potential format string bug. '
'Do printf("%s", foo->c_str()) instead.'
- ' [runtime/printf] [4]')
+ ' [security/printf] [4]')
self.assert_lint(
'StringPrintf(foo)',
'Potential format string bug. Do StringPrintf("%s", foo) instead.'
''
- ' [runtime/printf] [4]')
+ ' [security/printf] [4]')
# Variable-length arrays are not permitted.
def test_variable_length_array_detection(self):