From 04f4e673ca010619397c47f2d2631fb7b1c4633a Mon Sep 17 00:00:00 2001 From: Yingyuan Zhu Date: Wed, 29 Aug 2018 16:27:07 +0800 Subject: [PATCH] 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 --- drivers/amlogic/input/keyboard/adc_keypad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/amlogic/input/keyboard/adc_keypad.c b/drivers/amlogic/input/keyboard/adc_keypad.c index 61de3e35e7d8..a9f5ff9d5141 100644 --- a/drivers/amlogic/input/keyboard/adc_keypad.c +++ b/drivers/amlogic/input/keyboard/adc_keypad.c @@ -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)