Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1401947rwb; Fri, 13 Jan 2023 11:46:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXtp/rbZhe5ZmgSEg9pepmEGuCMFnGtN+q8lHLhfX6FaSpSXVabR8MgsdLfN+eNPp6/0kPtI X-Received: by 2002:a05:6a20:d496:b0:a7:a3cf:ddce with SMTP id im22-20020a056a20d49600b000a7a3cfddcemr92316573pzb.21.1673639162391; Fri, 13 Jan 2023 11:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673639162; cv=none; d=google.com; s=arc-20160816; b=C28jRJHB9/NKhe6RyHOtVb9KY0XdVeK6/FCykkV/Us89jJLpWMDLp1zJHDTp76kxfS 28J/jn4bLuEuUUdzzPGwt0k7HCzl2cY8gKQMuk7rThGyY27fWKabp0cthZD9q7HNiwL+ Kt4klrGxhjXmmGvIBR1ZUgNOSJrMyr5vMS8KXqZzRQm/Uig08mw9IGlq9piNI9Tc+T1S mDiCVaD1jZx0tCRYiEdB/MtCHrcTvPOA5HqAfPjEnWDM0q+wArLQH2XOaM7JGiaGAMu8 y5F+enr9e7vCE5Qp09YT7a4Z8EM8OvhvP521QZ7KAr9RR1pf08M999R4TqsTtHUc1dR1 cb+g== 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:subject:cc:to:from:date :dkim-signature; bh=qAqKDRF7BHMfrBfqKNUr9xFpG5ZGFmQZ/0e45+8xaeA=; b=1Gmz8OZRBqvX1xd3DWU0tXMz2iDcm7ImzcBgrZiJ289WZJsPNYCEZMcN6lQ8U/43tH oBTYnglFeJwZM58suTpdqYknM/idW4czMGK2+kdC7pDv8ZL95xTDfPgkmP3EiWjF4OFA eIuRwnDU8JjUuvBUna2tP6JTs+zNX4BMrUJILSxjGNMxEnWd1GgqzIZ+x+xsDKNH85nM S904BasnuC+C8Mcf0z+TIu/UcFKMHZozYQ28V2boXznQkkQjk3/d3hF40fjn0vkc3kgb XKcE9IqEQ1hpxS013ugvGVsmZxBnp8P4WyZk9oGebmCQciXQwVoBiBIauhBq0JLx7O1F U9Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BENo1rWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 n20-20020a635914000000b00498688359b6si21664088pgb.287.2023.01.13.11.45.55; Fri, 13 Jan 2023 11:46:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=BENo1rWj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S230016AbjAMT2x (ORCPT + 52 others); Fri, 13 Jan 2023 14:28:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjAMT2j (ORCPT ); Fri, 13 Jan 2023 14:28:39 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85C6C88A2F; Fri, 13 Jan 2023 11:28:20 -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 E687762309; Fri, 13 Jan 2023 19:28:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1EBDC433A4; Fri, 13 Jan 2023 19:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673638099; bh=oGTM2wuzaiQf3hnu49bV1kw3D+nqr4DgGLcbnBAxXKQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BENo1rWjURBUnC+mPcISq8IxkaNLrBFhEWK/AYiGE4tfQSoIP1w7gus2p5DUO58jW jv3F53pjzER1/aDCTJy+eaI6vv+SvSB6rY7AY3QoJAiGcUyiBYYuAoKYG3FygH/6UD y3WGEOSdP5B69oCN27m7Y7eDW2ScRFNhwIHtZ1IXBFfRY4yqhGu2sxfORzFXL/ww5j xS3Rewt5XXYAAhLw6oPB3cjhIIb0yFKyCSOJV690iyL8fTiXf0OGHwm+md7BP5aLhh 9k+szzOCOhj77HSBUrxPI385z7729wyoZ6Fc7H9hrFCQOkTtYehgo3DNAR/20pLiRu zY7INFFg05oeQ== Date: Fri, 13 Jan 2023 11:28:17 -0800 From: Jakub Kicinski To: Cc: , , , , , , , , Subject: Re: [PATCH net-next v2] net/rds: use strscpy() to instead of strncpy() Message-ID: <20230113112817.623f58fa@kernel.org> In-Reply-To: <202301131513124870047@zte.com.cn> References: <20230112211707.2abb31ad@kernel.org> <202301131513124870047@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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-kernel@vger.kernel.org On Fri, 13 Jan 2023 15:13:12 +0800 (CST) yang.yang29@zte.com.cn wrote: > > What are the differences in behavior between strncpy() and strscpy()? > > Strscpy() makes the dest string NUL-terminated, and returns more > useful value. While strncpy() can initialize the dest string. > > Here we use strscpy() to make dest string NUL-terminated, and use > return value to check src string size and dest string size. This make > the code simpler. I'm not sure whether in this particular case the output needs to be padded or not. And I'm not sure you understand what the implications are. The code is fine as is, and I don't trust that you know what you're doing. So please don't send any more strncpy() -> strscpy() conversions for networking. If you want to do something useful please start with adding a check to checkpatch to warn people against using strncpy() and suggest using strscpy() instead.