Skip to contentSkip to conversation

smb: server: Fix extension string in ksmbd_extract_shortname()

PATCH Applied Thorsten Blum 2 participants 2 messages Aug 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 smb: server: Fix extension string in ksmbd_extract_shortname()

In ksmbd_extract_shortname(), strscpy() is incorrectly called with the length of the source string (excluding the NUL terminator) rather than the size of the destination buffer. This results in "__" being copied to 'extension' rather than "___" (two underscores instead of three).

Use the destination buffer size instead to ensure that the string "___" (three underscores) is copied correctly.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")

---
Changes in v2:
- Use three parameter variant of strscpy() for easier backporting
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

---
 fs/smb/server/smb_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb_common.c +1 -1
index 425c756bcfb8..b23203a1c286 100644
@@ -515,7 +515,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname,
 
 	p = strrchr(longname, '.');
 	if (p == longname) { /*name starts with a dot*/
-		strscpy(extension, "___", strlen("___"));
+		strscpy(extension, "___", sizeof(extension));
 	} else {
 		if (p) {
 			p++;
Signature · 1 line
2.50.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Thorsten Blum

In ksmbd_extract_shortname(), strscpy() is incorrectly called with the length of the source string (excluding the NUL terminator) rather than the size of the destination buffer. This results in "__" being copied to 'extension' rather than "___" (two underscores instead of three).

Quoted 6 lines

Use the destination buffer size instead to ensure that the string "___" (three underscores) is copied correctly.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")

Applied it to #ksmbd-for-next-next.
Thanks!