From fa79a44270ea6186d35ca9a36b72beca614dd8a4 Mon Sep 17 00:00:00 2001 From: Olav Haugan Date: Mon, 6 Feb 2012 09:42:18 -0800 Subject: [PATCH] checkpatch: Check for unsafe string functions There are many string based functions that are unsafe to use. Some of the functions are unsafe to use because of the possibility of overflow while others cannot guarantee that the resultant string is NULL-terminated. Add check for these functions and log message indicating which safe functions can be used instead. Change-Id: Id305d98df241e3fd257529529739dcd4f3659186 Signed-off-by: Olav Haugan (cherry picked from commit 665be0da353f69f85cb1acea19279adf6ccb5b52) --- scripts/checkpatch.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 724dafb465eb..1570af9d9206 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3352,8 +3352,11 @@ sub process { # unbounded string functions are overflow risks my %str_fns = ( "sprintf" => "snprintf", - "strcpy" => "strncpy", - "strcat" => "strncat", + "strcpy" => "strlcpy", + "strncpy" => "strlcpy", + "strcat" => "strlcat", + "strncat" => "strlcat", + "vsprintf" => "vsnprintf", "strcmp" => "strncmp", "strcasecmp" => "strncasecmp", "strchr" => "strnchr",