From: Ferenc Wagner Date: Mon, 24 Oct 2011 14:53:50 +0000 (+1100) Subject: drivers/message/fusion/mptbase.c: ensure NUL-termination of MptCallbacksName elements X-Git-Tag: next-20111107~1^2~56 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=b5c7dd4bedba6339b2e24051708f496de457fd72;p=karo-tx-linux.git drivers/message/fusion/mptbase.c: ensure NUL-termination of MptCallbacksName elements I just stumbled upon this while pondering over https://bugzilla.kernel.org/show_bug.cgi?id=26692 and thought this could be made better. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Ferenc Wagner Cc: Desai Signed-off-by: Andrew Morton --- diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c index e9c6a6047a00..42db600826d6 100644 --- a/drivers/message/fusion/mptbase.c +++ b/drivers/message/fusion/mptbase.c @@ -115,7 +115,8 @@ module_param(mpt_fwfault_debug, int, 0600); MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault and halt Firmware on fault - (default=0)"); -static char MptCallbacksName[MPT_MAX_PROTOCOL_DRIVERS][50]; +static char +MptCallbacksName[MPT_MAX_PROTOCOL_DRIVERS][MPT_MAX_CALLBACKNAME_LEN + 1]; #ifdef MFCNT static int mfcounter = 0; @@ -717,8 +718,8 @@ mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass, char *func_name) MptDriverClass[cb_idx] = dclass; MptEvHandlers[cb_idx] = NULL; last_drv_idx = cb_idx; - memcpy(MptCallbacksName[cb_idx], func_name, - strlen(func_name) > 50 ? 50 : strlen(func_name)); + strlcpy(MptCallbacksName[cb_idx], func_name, + MPT_MAX_CALLBACKNAME_LEN+1); break; } } diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h index b4d24dc081ae..76c05bc24cb7 100644 --- a/drivers/message/fusion/mptbase.h +++ b/drivers/message/fusion/mptbase.h @@ -89,6 +89,7 @@ */ #define MPT_MAX_ADAPTERS 18 #define MPT_MAX_PROTOCOL_DRIVERS 16 +#define MPT_MAX_CALLBACKNAME_LEN 49 #define MPT_MAX_BUS 1 /* Do not change */ #define MPT_MAX_FC_DEVICES 255 #define MPT_MAX_SCSI_DEVICES 16