Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8987872ybi; Tue, 23 Jul 2019 19:32:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmnsu3iWaA2Bnq4bvoNjZXKUgqZqY8Gosj8Uh4TdBoyuh52c+OJE0wNjRwx48xEx8sgLva X-Received: by 2002:a17:90a:bb0c:: with SMTP id u12mr86586870pjr.132.1563935541096; Tue, 23 Jul 2019 19:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563935541; cv=none; d=google.com; s=arc-20160816; b=YTaB/9yWL5fT4ZjJUO+O0lgsOoMYKZeo42OezMrGPeOtHuETFxR2iMpow0rX0Gzgag 3Db8NNaa5xOAth/AO+LfmOGgEUjr28vGrHBs1gz/zz8W/5adJ/PLHe1Cv/yt3LfEZoKr vNsEYNPjsgGZ2WhXzH2Fdqmd/e0Or4HB4tQxLljNZ17+zZq1cB/AYLgMRwocgnA3rGnX lCCuNw+rZE9vf3XgUaJTJvnmVCjTwDVKoIJfIkHMwbYTdYu+TMV7EbFip83InGvgaViT HLi63eFUhZE1p6CNckOxQQC+mFmywsbi/elDxzLtBMqFg/LJ6qJHffvdOc0MkbSqUgnv bFkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=9UxXAEn1d4ehdiyZoh8T+u3HvYQnpM2jmP/WcKAML7o=; b=lC3lUdnt9C61T8+fe0fnTgKbNRbEvAdl/DO3XW67isrVYXWVusvqM9nDvGwvC8F321 rpssD3rQpKBnEkqzFSpkV5yoWWm18UtjmaIH5QpalAC2tud7gPGPL27k0Nbb9DPGcpev j63TJuRgY+tlBmHQjvpDYIAYqHWpoeF5wrjTBwf+xYUNjhyMyMeQBmRK9HH3kHyxTDPm WwCeuLEaYePFFVsV6fy9s7ZizT62SiEbAVXpXaUTHJJTMy5jBuqexozBkbJMrINNa7uV I7pOubAPRAxxrcLqdSHcSzBJIMRVY0JVlwnDcxoi12/G4VaYIehZVz4ULZra6xPkLVJD 3rLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si14403079pgv.135.2019.07.23.19.32.05; Tue, 23 Jul 2019 19:32:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391915AbfGWUwe (ORCPT + 99 others); Tue, 23 Jul 2019 16:52:34 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:49394 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbfGWUwd (ORCPT ); Tue, 23 Jul 2019 16:52:33 -0400 X-IronPort-AV: E=Sophos;i="5.64,300,1559512800"; d="scan'208";a="393054747" Received: from c-73-22-29-55.hsd1.il.comcast.net (HELO hadrien) ([73.22.29.55]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jul 2019 22:52:32 +0200 Date: Tue, 23 Jul 2019 15:52:30 -0500 (CDT) From: Julia Lawall X-X-Sender: jll@hadrien To: Joe Perches cc: cocci , LKML Subject: Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms] In-Reply-To: <66fcdbf607d7d0bea41edb39e5579d63b62b7d84.camel@perches.com> Message-ID: References: <7ab8957eaf9b0931a59eff6e2bd8c5169f2f6c41.1563841972.git.joe@perches.com> <66fcdbf607d7d0bea41edb39e5579d63b62b7d84.camel@perches.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 22 Jul 2019, Joe Perches wrote: > Hello Julia. > > I just sent a patch to add yet another string copy mechanism. > > This could help avoid misuses of strscpy and strlcpy like this > patch set: > > https://lore.kernel.org/lkml/cover.1562283944.git.joe@perches.com/T/ > > A possible cocci script to do conversions could be: > > $ cat str.cpy.cocci > @@ > expression e1; > expression e2; > @@ > > - strscpy(e1, e2, sizeof(e1)) > + stracpy(e1, e2) > > @@ > expression e1; > expression e2; > @@ > > - strlcpy(e1, e2, sizeof(e1)) > + stracpy(e1, e2) > > This obviously does not match the style of all the > scripts/coccinelle cocci files, but this might be > something that could be added improved and added. > > This script produces: > > $ spatch --in-place -sp-file str.cpy.cocci . > $ git checkout tools/ > $ git diff --shortstat > 958 files changed, 2179 insertions(+), 2655 deletions(-) > > The remainder of strlcpy and strscpy uses in the > kernel would generally have a form like: > > strlcpy(to, from, DEFINE) > > where DEFINE is the specified size of to > > Could the cocci script above be updated to find > and correct those styles as well? I guess it would depend on what "to" is and what DEFINE expands into. For example, in cpuidle-powernv.c, I see: strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN); and by poking around I see: struct cpuidle_state { char name[CPUIDLE_NAME_LEN]; char desc[CPUIDLE_DESC_LEN]; ... }; So I guess this case is ok. I will look into it. thanks, julia