Skip to contentSkip to conversation

misc: eeprom/idt_89hpesx: use strscpy() to instead of strncpy()

PATCH New [email protected] 1 participant 1 message Dec 7, 2022 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: eeprom/idt_89hpesx: use strscpy() to instead of strncpy()

From: Xu Panda <[email protected]>

The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.

---
 drivers/misc/eeprom/idt_89hpesx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/eeprom/idt_89hpesx.c +1 -2
index 4e07ee9cb500..57b985fe59f4 100644
@@ -941,8 +941,7 @@ static ssize_t idt_dbgfs_csr_write(struct file *filep, const char __user *ubuf,
 			goto free_buf;
 		}
 		/* Copy the register address to the substring buffer */
-		strncpy(csraddr_str, buf, csraddr_len);
-		csraddr_str[csraddr_len] = '\0';
+		strscpy(csraddr_str, buf, csraddr_len + 1);
 		/* Register value must follow the colon */
 		csrval_str = colon_ch + 1;
 	} else /* if (str_colon == NULL) */ {
Signature · 1 line
2.15.2