From cbc58a68740333a6dcf75a2a948a1f48707cd4ce Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 15 Sep 2021 10:59:14 +0200 Subject: [PATCH] lint: checkpatch.pl: add STRCPY_OSMO Add Osmocom specific check to forbid using strncpy() and strcpy(). Instead, osmo_strlcpy() or OSMO_STRLCPY_ARRAY() should be used. Related: OS#5087 Related: https://lists.osmocom.org/pipermail/openbsc/2021-September/013538.html Change-Id: I6fa96c8f3d15110dd3d3509faa593285a78f469e --- lint/checkpatch/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lint/checkpatch/checkpatch.pl b/lint/checkpatch/checkpatch.pl index 059a2a6c..06e6e36f 100755 --- a/lint/checkpatch/checkpatch.pl +++ b/lint/checkpatch/checkpatch.pl @@ -7201,6 +7201,13 @@ sub process { "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr); } +# Osmocom specific: check for strncpy(), strcpy() +# https://lists.osmocom.org/pipermail/openbsc/2021-September/013538.html + if ($line =~ /\bstr(n)?cpy\(/) { + ERROR("STRCPY_OSMO", + "Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()\n" . $herecurr); + } + # check for deprecated apis if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) { my $deprecated_api = $1;