Skip to contentSkip to conversation

module: Replace deprecated strncpy() with strscpy()

PATCH In review Thorsten Blum 2 participants 2 messages Mar 7, 2025 – Mar 10, 2025 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module: Replace deprecated strncpy() with strscpy()

strncpy() is deprecated for NUL-terminated destination buffers; use strscpy() instead. The destination buffer ownername is only used with "%s" format strings and must therefore be NUL-terminated, but not NUL- padded.

No functional changes intended.

---
 kernel/module/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/module/main.c +1 -1
index 1fb9ad289a6f..2b88c91c89e3 100644
@@ -1189,7 +1189,7 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
 
 getname:
 	/* We must make copy under the lock if we failed to get ref. */
-	strncpy(ownername, module_name(fsa.owner), MODULE_NAME_LEN);
+	strscpy(ownername, module_name(fsa.owner), MODULE_NAME_LEN);
 unlock:
 	mutex_unlock(&module_mutex);
 	return fsa.sym;
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 10 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers; use strscpy() instead. The destination buffer ownername is only used with "%s" format strings and must therefore be NUL-terminated, but not NUL- padded.

No functional changes intended.

Looks good to me. I've queued it on modules-next.

Signature · 2 lines
Thanks,
Petr