Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4469604rwb; Sat, 21 Jan 2023 12:38:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXtPuhz81ru5I8jtJPgeiMLAgYsHZIa/QdDZ7NWCvrTq5oFvMXhOmzJxlWHTeBh3XJYd8amX X-Received: by 2002:a05:6a21:170d:b0:b6:3a0:6ec1 with SMTP id nv13-20020a056a21170d00b000b603a06ec1mr18080048pzb.25.1674333487348; Sat, 21 Jan 2023 12:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674333487; cv=none; d=google.com; s=arc-20160816; b=Am1mYzPYgVYOYfxA8lccrWdAxrDtA/SO8i31hGNllcLCXhoyT3sg112G3Z6VMW/qaK yt0cbdTNhZhaIeLARyhjNMOM1Q3Lgez9/A9k8R1mltUpQ8OsIaeeeqAQcUFgBtQ7n2/h vLO6BwjnWiJZrvthXM7s8pBEmNtzGcZoMqMi73gtgGP8M6wKiQ3xqNdh7zwCMWJZhfRe AhGvsMFBVoRR1dN2tooU7iB6IsqE6fhTbTnXfp34YJ25Zgvu7hDb8Z5aVKhir9iqqOxZ CuLMqxTw7ZaI+Rf6Uzr4uH3Y/3N6uMxusI4rgdvzSqPoSLPsoTD2HCLhqOUJ/he6GRsW sxoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=8jhLWwfoEtVcevFRQB5UzL5V91jOpp+gHPXLGad915Y=; b=CRAUXMR2uCM8CZp/3JkymydV2kAyv44v/zeui5sDWsaBC6rC/akco+/HnVa9SKpC7t n5yMOb+4A87KeN2kS/UjIj9ogVv0ECplxOiOHCyHFpTKMQQ9ht+yiev2V5mz9hMO8vnB jUgIUOBDIqgGXJJQZMe/A+ziDp3hBShhkUm3Nqo3kaizldVymnA2cNmjvqpg3t89vv2+ 7HboC4kQvsni12V1dlM4hXASY8L4GLh/zibGPYCTJ9wrl3yIuA5WORIoLGEjMj088jBH VIIFRIxKDZYTaSMU8KeFugNgldId01laN873D5KMJk+R+9e3jzMSFvt+gRl2CwA1sZzv 6vOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QKTyeFqK; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q71-20020a632a4a000000b004a3ed20c3dbsi47121951pgq.454.2023.01.21.12.37.53; Sat, 21 Jan 2023 12:38:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QKTyeFqK; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbjAUUhP (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit 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; } -- 2.39.0