meson: adc_key: fix coverity warning

PD#172717: meson: adc_key: fix coverity warning

The "strncpy" function does not ensure that
the string "key->name"ends with a null character.
So, the function "strncpy" is replaced by the function "snprintf".
This causes "Buffer not null terminated".

Change-Id: I83cd35f2df8790ca779a8cc8bcde1cd97f2c9020
Signed-off-by: Yingyuan Zhu <yingyuan.zhu@amlogic.com>
This commit is contained in:
Yingyuan Zhu
2018-08-29 16:27:07 +08:00
committed by Jianxin Pan
parent 343d627172
commit 04f4e673ca

View File

@@ -253,7 +253,7 @@ static int meson_adc_kp_get_devtree_pdata(struct platform_device *pdev,
state = -EINVAL;
goto err;
}
strncpy(key->name, uname, MAX_NAME_LEN);
snprintf(key->name, MAX_NAME_LEN, "%s", uname);
ret = of_property_read_u32_index(pdev->dev.of_node,
"key_code", cnt, &key->code);
@@ -399,7 +399,7 @@ static ssize_t table_store(struct class *cls, struct class_attribute *attr,
/*save the key data in order*/
pval = strsep(&pbuf, ":"); /*name*/
if (pval)
strncpy(dkey->name, pval, MAX_NAME_LEN);
snprintf(dkey->name, MAX_NAME_LEN, "%s", pval);
pval = strsep(&pbuf, ":"); /*code*/
if (pval)