From patchwork Sat Jan 21 20:32:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 1730074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=gbep=5s=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=QKTyeFqK; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nzp7x51sbz23gY for ; Sun, 22 Jan 2023 07:37:17 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nzp7x4bJBz4xN1 for ; Sun, 22 Jan 2023 07:37:17 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Nzp7x4Xrtz4y03; Sun, 22 Jan 2023 07:37:17 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=QKTyeFqK; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nzp7x4RXmz4xN1 for ; Sun, 22 Jan 2023 07:37:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229895AbjAUUhP (ORCPT ); Sat, 21 Jan 2023 15:37:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjAUUgt (ORCPT ); Sat, 21 Jan 2023 15:36:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A9329176 for ; Sat, 21 Jan 2023 12:36:45 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A43AA60B92 for ; Sat, 21 Jan 2023 20:36:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CAE9C433EF for ; Sat, 21 Jan 2023 20:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674333404; bh=VEkoFq9DgQ/t9PgvjnI05sXJeWdbDnvI1z7dx9j6ORI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QKTyeFqKJTgVz/2ybdDJkBkseGND2s+vADrnwlaxeOWHgPD9nSHGVJO8xCllOakid YhIiPDI2wi5RMCI5N7tC9tfXiLHoj4Io34/bjy+1dxGHWhBxyTPVGFaUl/H0N7SwDi KLjWD5begeqGBXpWj4AqBsgrU0+vd87JPiGHb/LpNNhbasTWT2fTVWHHzEB21ifqP2 yErNCS8ZltB/OnPZk0fY8Y92q5Kp/cF0P6PpG7nUI8uXq4uY7UIh8qKpXSGytaaU58 nSYP5Ce9QpkkV9MQAnY4Cm1Kp1ph1PM9FVnJddp3FJy1XcWdKHCe8SL2vvM+BzBMNQ B5J+is2gez01g== From: Eric Biggers To: linux-ext4@vger.kernel.org Subject: [PATCH 30/38] misc/fuse2fs: avoid error-prone strncpy() pattern Date: Sat, 21 Jan 2023 12:32:22 -0800 Message-Id: <20230121203230.27624-31-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121203230.27624-1-ebiggers@kernel.org> References: <20230121203230.27624-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers 'strncpy(dst, src, strlen(src))' is usually wrong, as it doesn't copy the null terminator. For this reason, it causes a -Wstringop-truncation warning with gcc 8 and later. The code happens to be correct anyway, since the destination buffer is zero-initialized. But to avoid relying on this, let's just copy the terminating null. Signed-off-by: Eric Biggers --- misc/fuse2fs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index c59572129..6d4bcf4fd 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -2508,9 +2508,10 @@ static int copy_names(char *name, char *value EXT2FS_ATTR((unused)), size_t value_len EXT2FS_ATTR((unused)), void *data) { char **b = data; + size_t name_len = strlen(name); - strncpy(*b, name, strlen(name)); - *b = *b + strlen(name) + 1; + memcpy(*b, name, name_len + 1); + *b = *b + name_len + 1; return 0; }