diff mbox series

[v6,7/9] soc: qcom: wcnss_ctrl: Avoid string overflow

Message ID 20180829075724.9095-8-niklas.cassel@linaro.org (mailing list archive)
State Accepted, archived
Delegated to: Andy Gross
Headers show
Series soc: qcom: Allow COMPILE_TEST of qcom SoC Kconfigs | expand

Commit Message

Niklas Cassel Aug. 29, 2018, 7:57 a.m. UTC
'chinfo.name' is used as a NUL-terminated string, but using strncpy() with
the length equal to the buffer size may result in lack of the termination:

drivers//soc/qcom/wcnss_ctrl.c: In function 'qcom_wcnss_open_channel':
drivers//soc/qcom/wcnss_ctrl.c:284:2: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
  strncpy(chinfo.name, name, sizeof(chinfo.name));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This changes it to use the safer strscpy() instead.

Signed-off-by: Niklas Cassel <niklas.cassel@linaro.org>
---
 drivers/soc/qcom/wcnss_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bjorn Andersson Sept. 3, 2018, 7:22 p.m. UTC | #1
On Wed 29 Aug 00:57 PDT 2018, Niklas Cassel wrote:

> 'chinfo.name' is used as a NUL-terminated string, but using strncpy() with
> the length equal to the buffer size may result in lack of the termination:
> 
> drivers//soc/qcom/wcnss_ctrl.c: In function 'qcom_wcnss_open_channel':
> drivers//soc/qcom/wcnss_ctrl.c:284:2: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
>   strncpy(chinfo.name, name, sizeof(chinfo.name));
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This changes it to use the safer strscpy() instead.
> 
> Signed-off-by: Niklas Cassel <niklas.cassel@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  drivers/soc/qcom/wcnss_ctrl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/qcom/wcnss_ctrl.c b/drivers/soc/qcom/wcnss_ctrl.c
> index df3ccb30bc2d..373400dd816d 100644
> --- a/drivers/soc/qcom/wcnss_ctrl.c
> +++ b/drivers/soc/qcom/wcnss_ctrl.c
> @@ -281,7 +281,7 @@ struct rpmsg_endpoint *qcom_wcnss_open_channel(void *wcnss, const char *name, rp
>  	struct rpmsg_channel_info chinfo;
>  	struct wcnss_ctrl *_wcnss = wcnss;
>  
> -	strncpy(chinfo.name, name, sizeof(chinfo.name));
> +	strscpy(chinfo.name, name, sizeof(chinfo.name));
>  	chinfo.src = RPMSG_ADDR_ANY;
>  	chinfo.dst = RPMSG_ADDR_ANY;
>  
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/soc/qcom/wcnss_ctrl.c b/drivers/soc/qcom/wcnss_ctrl.c
index df3ccb30bc2d..373400dd816d 100644
--- a/drivers/soc/qcom/wcnss_ctrl.c
+++ b/drivers/soc/qcom/wcnss_ctrl.c
@@ -281,7 +281,7 @@  struct rpmsg_endpoint *qcom_wcnss_open_channel(void *wcnss, const char *name, rp
 	struct rpmsg_channel_info chinfo;
 	struct wcnss_ctrl *_wcnss = wcnss;
 
-	strncpy(chinfo.name, name, sizeof(chinfo.name));
+	strscpy(chinfo.name, name, sizeof(chinfo.name));
 	chinfo.src = RPMSG_ADDR_ANY;
 	chinfo.dst = RPMSG_ADDR_ANY;