lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Fri, 20 Oct 2023 19:21:46 +0000
From: Justin Stitt <>
To: Sebastian Reichel <>
Cc:,,, Justin Stitt <>
Subject: [PATCH] power: supply: charger-manager: replace deprecated strncpy
 with strscpy

strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string

We expect cm->psy_name_buf to be NUL-terminated based on its usage with
format strings:
1522: cm-> = cm->psy_name_buf;
1587: dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
1587:   cm->;

Moreover, NUL-padding is not required as `cm` is already zero-allocated
and thus any future NUL-byte assignments (like what strncpy() will do)
are redundant:
1437: cm = devm_kzalloc(&pdev->dev, sizeof(*cm), GFP_KERNEL);

Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without unnecessarily NUL-padding.

Let's also opt for the more idiomatic strscpy() usage of:
strscpy(dest, src, sizeof(dest)).

Link: [1]
Link: [2]
Signed-off-by: Justin Stitt <>
Note: build-tested only.

Found with: $ rg "strncpy\("
 drivers/power/supply/charger-manager.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index 5fa6ba7f41e1..085d5277bc19 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1516,9 +1516,11 @@ static int charger_manager_probe(struct platform_device *pdev)
 	memcpy(&cm->charger_psy_desc, &psy_default, sizeof(psy_default));
 	if (!desc->psy_name)
-		strncpy(cm->psy_name_buf,, PSY_NAME_MAX);
+		strscpy(cm->psy_name_buf,,
+			sizeof(cm->psy_name_buf));
-		strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX);
+		strscpy(cm->psy_name_buf, desc->psy_name,
+			sizeof(cm->psy_name_buf));
 	cm-> = cm->psy_name_buf;
 	/* Allocate for psy properties because they may vary */

base-commit: bb55d7f7f7445abcc8db50e6a65d4315e79f75c7
change-id: 20231020-strncpy-drivers-power-supply-charger-manager-c-236767ef929c

Best regards,
Justin Stitt <>

Powered by blists - more mailing lists