diff --git a/.lintrunner.toml b/.lintrunner.toml index 2ca0c0fd394..741398648f3 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -732,3 +732,28 @@ init_command = [ '--requirement=requirements-lintrunner.txt', ] is_formatter = true + + +[[linter]] +code = 'CPP_BANNED_FUNCTIONS' +include_patterns = [ + 'examples/arm/**/*.c', + 'examples/arm/**/*.cc', + 'examples/arm/**/*.cpp', + 'examples/arm/**/*.h', + 'examples/arm/**/*.hpp', +] +exclude_patterns = [ + 'third-party/**', + '**/third-party/**', +] +command = [ + 'python', + '-m', + 'lintrunner_adapters', + 'run', + 'cpp_banned_functions_linter', + '--config=backends/arm/scripts/banned_functions.json', + '--', + '@{{PATHSFILE}}', +] diff --git a/backends/arm/scripts/LICENSE-MIT b/backends/arm/scripts/LICENSE-MIT new file mode 100644 index 00000000000..9c2baaac22e --- /dev/null +++ b/backends/arm/scripts/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright 2026 Arm Limited and/or its affiliates + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/backends/arm/scripts/banned_functions.json b/backends/arm/scripts/banned_functions.json new file mode 100644 index 00000000000..e906eef9030 --- /dev/null +++ b/backends/arm/scripts/banned_functions.json @@ -0,0 +1,107 @@ +{ + "banned_functions": [ + { + "names": ["alloca"], + "replacements": ["malloc", "new"] + }, + { + "names": ["gets"], + "replacements": ["fgets"] + }, + { + "names": ["memcpy"], + "replacements": ["memcpy_s"] + }, + { + "names": ["wmemcpy"], + "replacements": ["wmemcpy_s"] + }, + { + "names": ["memmove"], + "replacements": ["memmove_s"] + }, + { + "names": ["wmemmove"], + "replacements": ["wmemmove_s"] + }, + { + "names": ["readdir_r"], + "replacements": ["readdir"] + }, + { + "names": ["scanf", "wscanf", "_tscanf", "sscanf", "swscanf", "_stscanf"], + "replacements": ["fgets"] + }, + { + "names": [ + "strcat", + "wcscat", + "_tcscat", + "_mbscat", + "StrCat", + "lstrcat", + "lStrCatBuff", + "_tccat", + "_mbccat", + "_ftcscat", + "strncat", + "wcsncat", + "_tcsncat", + "_mbsncat", + "_mbsnbcat", + "StrCatN", + "StrNCat", + "lstrncat", + "lstrcatn" + ], + "replacements": ["strcat_s", "strncat_s"] + }, + { + "names": [ + "strcpy", + "wcscpy", + "_tcscpy", + "_mbscpy", + "StrCpy", + "lstrcpy", + "_tccpy", + "_mbccpy", + "_ftcscpy", + "strncpy", + "wcsncpy", + "_tcsncpy", + "_mbsncpy", + "_mbsnbcpy", + "StrCpyN", + "StrNCpy", + "lstrcpyn" + ], + "replacements": ["strcpy_s", "strncpy_s"] + }, + { + "names": ["strlen"], + "replacements": ["strnlen_s"] + }, + { + "names": ["wcslen"], + "replacements": ["wcsnlen_s"] + }, + { + "names": ["strtok", "_tcstok", "wcstok", "_mbstok"], + "replacements": ["strtok_s"] + }, + { + "names": [ + "wsprintf", + "sprintf", + "swprintf", + "_stprintf", + "wvsprintf", + "vsprintf", + "_vstprintf", + "vswprintf" + ], + "replacements": ["snprintf", "snprintf_s"] + } + ] +} diff --git a/backends/arm/scripts/banned_functions.json.license b/backends/arm/scripts/banned_functions.json.license new file mode 100644 index 00000000000..31207b7febd --- /dev/null +++ b/backends/arm/scripts/banned_functions.json.license @@ -0,0 +1,5 @@ +SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates +SPDX-License-Identifier: MIT + +File copied from https://github.com/justinchuby/lintrunner-adapters/ which has an MIT license. +File permalink: https://github.com/justinchuby/lintrunner-adapters/blob/772e5936d9b02814e29e12ca1355d33b029688c2/examples/adapters/cpp_banned_functions_linter/example_banned_functions.json diff --git a/examples/arm/executor_runner/arm_executor_runner.cpp b/examples/arm/executor_runner/arm_executor_runner.cpp index 1b4a3816886..f894634cabc 100644 --- a/examples/arm/executor_runner/arm_executor_runner.cpp +++ b/examples/arm/executor_runner/arm_executor_runner.cpp @@ -485,7 +485,10 @@ Error prepare_input_tensors( } else if (input_evalues[i].isTensor()) { // Copy the data from the input buffer to the tensor Tensor& tensor = input_evalues[i].toTensor(); - std::memcpy(tensor.mutable_data_ptr(), buffer, buffer_size); + std::memcpy( // NOLINT(memcpy) - Buffer size is checked + tensor.mutable_data_ptr(), + buffer, + buffer_size); } } diff --git a/requirements-dev.txt b/requirements-dev.txt index 016cf2a559d..4190bd11093 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,7 +9,7 @@ wheel # For building the pip package archive. zstd # Imported by resolve_buck.py. certifi # Imported by resolve_buck.py. lintrunner==0.12.7 -lintrunner-adapters==0.14.0 +lintrunner-adapters==0.14.1 ruff==0.15.4 pytest<9.0