From nobody Tue Dec 2 02:19:01 2025 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B4812E3AEA for ; Wed, 19 Nov 2025 13:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763557376; cv=none; b=WEahyQquScS3Ouq5/yhrMCNf1nUoCGmra3OsYoNWFsI4gu1eq91F1AaDnCnovjAG3CxZgscb7OvU8Wybs/6yUFQrXenQfzhhcftmCNEj4ltv9+b9AaU8Xd0eoNYoftrc9Q9IUjztfCf1p8IIsYw7xQf5n4Yvzigz3A12gr8ZBGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763557376; c=relaxed/simple; bh=lokf8+0AvhEyv7vqXFg5/f3662WM7AqTStYVDGufHvg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=B7INHIsT2JYUQsWOs3PyGzNWa9S5n/3JB3v5QBDnrKhHluZa6eqrs0XoSkHVohTBqPHA7bpw/Yn8eLuxt57dPXmkvmmHgU5WPRwA/3YkDhXX86WjTmAM4OIKyF4bgcqVqzYbo1LbYFiHky/GthmBteabK4b6YoE2so7D4x92nbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XXNOaOxC; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XXNOaOxC" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763557372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2KXDy9PdC32jEAfsmQBmrN4zOWZ8tgVUzdmSzfFa5hw=; b=XXNOaOxCH++JhF0el1ubtHdpSNrOrHuJpik9pO/8ejl6J2UVl9f07YwZcWR7sFN976eoML mApEM4s1C9NyHNUxuCO1gxX2lrVGR7LG2//YfaVGl3giX/DjqHSnnD3MB5zH1EE2TkNAUD oLMRfyoTDtAjjANh66s3+Ep2poK/OaQ= From: Thorsten Blum To: David Laight , Namjae Jeon , Steve French , Sergey Senozhatsky , Tom Talpey Cc: Thorsten Blum , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ksmbd: Replace strcpy + strcat to improve convert_to_nt_pathname Date: Wed, 19 Nov 2025 14:02:30 +0100 Message-ID: <20251119130231.171352-1-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" strcpy() is deprecated [1] and using strcat() is discouraged. Replace them by assigning the prefix directly and by using memcpy() to copy the pathname. Using memcpy() is safe because we already know the length of the source string and that it is guaranteed to be NUL-terminated. Allocate only as many bytes as needed and replace kzalloc() with kmalloc() since memcpy() overwrites the entire buffer anyway. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy= [1] Signed-off-by: Thorsten Blum --- Changes in v2: - Assign the prefix directly if needed - Use memcpy() instead of scnprintf() (David) - Allocate only as many bytes as needed - Replace kzalloc() with kmalloc() - Update patch title and description - Link to v1: https://lore.kernel.org/lkml/20251118122555.75624-2-thorsten.= blum@linux.dev/ --- fs/smb/server/misc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/smb/server/misc.c b/fs/smb/server/misc.c index cb2a11ffb23f..a543ec9d3581 100644 --- a/fs/smb/server/misc.c +++ b/fs/smb/server/misc.c @@ -164,6 +164,8 @@ char *convert_to_nt_pathname(struct ksmbd_share_config = *share, { char *pathname, *ab_pathname, *nt_pathname; int share_path_len =3D share->path_sz; + size_t ab_pathname_len; + int prefix; =20 pathname =3D kmalloc(PATH_MAX, KSMBD_DEFAULT_GFP); if (!pathname) @@ -180,15 +182,18 @@ char *convert_to_nt_pathname(struct ksmbd_share_confi= g *share, goto free_pathname; } =20 - nt_pathname =3D kzalloc(strlen(&ab_pathname[share_path_len]) + 2, - KSMBD_DEFAULT_GFP); + ab_pathname_len =3D strlen(&ab_pathname[share_path_len]); + prefix =3D ab_pathname[share_path_len] =3D=3D '\0' ? 1 : 0; + nt_pathname =3D kmalloc(prefix + ab_pathname_len + 1, KSMBD_DEFAULT_GFP); if (!nt_pathname) { nt_pathname =3D ERR_PTR(-ENOMEM); goto free_pathname; } - if (ab_pathname[share_path_len] =3D=3D '\0') - strcpy(nt_pathname, "/"); - strcat(nt_pathname, &ab_pathname[share_path_len]); + + if (prefix) + *nt_pathname =3D '/'; + memcpy(nt_pathname + prefix, &ab_pathname[share_path_len], + ab_pathname_len + 1); =20 ksmbd_conv_path_to_windows(nt_pathname); =20 --=20 2.51.1