Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp558821imm; Fri, 13 Jul 2018 02:16:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeGOyHKaS2RNzl9Vy0kSvVq8GJn5tIl9l+dW2w+MHqnUCHm4wuwW0m8EPyO2RZPtZHvNFZx X-Received: by 2002:aa7:8118:: with SMTP id b24-v6mr6220985pfi.78.1531473379804; Fri, 13 Jul 2018 02:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531473379; cv=none; d=google.com; s=arc-20160816; b=SYxFjd+kzN3qD2Zj6znii5Y+aB7wFvdRZ/MutlLS1VoXmJ2v39NYai77t4hJBjuWFt MqiEoxpSw/508uw/uvYI0adDDXka5O9sY3BOGN/WFsxV3ujD492MVIlBcoiuZigbqqH/ 58ZDUQhAnDMhYxRVlKaKVB5PwhnM0gXHO8N+kOPsCcjQGFVfqF9rt35N1w0hC6bAj95Z Ca2z2hHIHoIkGOffQWiMCsCwN3c4Iu2uSeZV58VRT8KIvf3WhvvTyW8kLL5udojTuxCi wjjYIoXyuPUTbqIfXnQLCfRoDV6piuZXsKJYyjr4YEScuakGVlcaxhGBPMvHM0ONOJuF L/Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=qUL9eRb7CMCPznzPEAIGrich6NgUhKSPLc5d4ZDuCQk=; b=heLC/gi0KiarL483t5eUwsfHRWJaGIBkK5kEPJitlFkrgubU8E8t9Z/vlpg8638dIB 8QoMJ+iDDRii6PbOAZuDIITlxfYxGav6yHb4pG4PNTirtW8QLrMPpDT1fPNNMy/WPcur upDvk2nTsETlKn3Do2tYMthJ58y+NngvLwDoAsQ7Joe61477x6BHvoA8mFcCiEzMcf0z khKYDM3df929grNVf9pqkVG6EqL6bkuuRgABCsFfjDWm6B70JHFQNmxk9yQj/fPNKgSu E2sb3EstoNXVHgAtHWk4zPEJgQkPjDiL2OE7Zr3EyuvyC/acpE8c2HWMZMCJvAFsHM4N wiZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ve4cfl1q; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f40-v6si24015476plb.504.2018.07.13.02.16.04; Fri, 13 Jul 2018 02:16:19 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ve4cfl1q; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729670AbeGMJ2G (ORCPT + 99 others); Fri, 13 Jul 2018 05:28:06 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35159 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbeGMJ2G (ORCPT ); Fri, 13 Jul 2018 05:28:06 -0400 Received: by mail-pf0-f193.google.com with SMTP id q7-v6so21210082pff.2 for ; Fri, 13 Jul 2018 02:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qUL9eRb7CMCPznzPEAIGrich6NgUhKSPLc5d4ZDuCQk=; b=ve4cfl1qFL0m2pQFW37wo9n1lAso2jbkKFZD1FkORRQJrEwFDF9P2I2iT6xA3+Vgad leyzgz3f4jUg9Vix47bei1OFHgx1LH4kMoQ6RSWDmjjGhyedwTje+i+pInuSMF9abLDl jR+1deseLwDUUypDEANn5QnIoAkCr0N53AAXCQuAJp6J6GtbSnWGc/wfHFoPu4ddWHPB 4q64XF5cmcrpvrd7u5hfo/JEFq5i+IWtLAswf39czMhIITkeVHXJV4ctk3HVo6ePQbH0 Iq3wrvFKX6W8mg7TDocdw83g5cLQOI2kQS08fcmh4fv0yCUyqWkfPgDa40QUhoc0dkJZ 0NDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qUL9eRb7CMCPznzPEAIGrich6NgUhKSPLc5d4ZDuCQk=; b=ceSCINEQWFeJ/60SowRHkivICfllGv96WhlOTuyhieHkx56q9z88uYGLWfZgOXrocY 0NGoihzNSmx5KOm72gqrJf5HN8eKhHe7sa9oar1c0QbUDSEzyiJg+q2I/iKyJ8s6Iuj/ WoRbDOthqk9QtqGrgObbS2t9GOpJwFlJoykNo/mSWqGK23CN326G+pn3d9nUbvYNpt2D YXItwnVwLUN+wP7/R8cPbo8sETcCwgzR3Gkpmqyju5Bu7Q7LZbGljHWrj9RGRvTIVZxy LeQIbNzT1cVOPJI/DxC6xjw00xpoRrTrpq6KsoPaWCM8BT2eKFFOzvZSgg0mScEHAeHx waFQ== X-Gm-Message-State: AOUpUlG8yMKKaW4BNN/brzpo4mzOXQWMtAWJKQwyUTBjc1MYrFLi2ADm 6J54ONh+DjL+SCDUREZ3PX4= X-Received: by 2002:a62:9cd7:: with SMTP id u84-v6mr6216595pfk.90.1531473260040; Fri, 13 Jul 2018 02:14:20 -0700 (PDT) Received: from himanshu-Vostro-3559 ([103.233.116.134]) by smtp.gmail.com with ESMTPSA id a191-v6sm24692919pge.45.2018.07.13.02.14.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 02:14:19 -0700 (PDT) Date: Fri, 13 Jul 2018 14:44:12 +0530 From: Himanshu Jha To: Dominique Martinet Cc: Michal Marek , Nicolas Palix , linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr, Ville =?iso-8859-1?Q?Syrj=E4l=E4?= Subject: Re: [Cocci] [PATCH 01/18] coccinelle: change strncpy+truncation to strlcpy Message-ID: <20180713091412.GA11250@himanshu-Vostro-3559> References: <1531444483-17338-1-git-send-email-asmadeus@codewreck.org> <20180713074455.GA6859@himanshu-Vostro-3559> <20180713080023.GB9638@nautica> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180713080023.GB9638@nautica> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 13, 2018 at 10:00:23AM +0200, Dominique Martinet wrote: > Himanshu Jha wrote on Fri, Jul 13, 2018: > > > I expect each maintainer will pick their share of the patchs if they > > > agree with it and the rest will just be dropped? > > > > Masahiro Yamada takes coccinelle patches, > > so please cc him or your patch would be lost. > > Thanks, will do. > > > > +virtual patch > > > +virtual context > > > > You might consider adding context rule or remove this line perhaps ? > > Victim of copypasta, I'll remove this. > > > > +-strncpy@p( > > > ++strlcpy( > > > + dest, src, sz); > > > +-dest[sz - 1] = '\0'; > > > > The above rule produces an output that I think is not correct: > > -------------------------------------------------------------- > > diff = > > diff -u -p a//ti/wl1251/acx.c b//ti/wl1251/acx.c > > --- a//ti/wl1251/acx.c > > +++ b//ti/wl1251/acx.c > > @@ -150,14 +150,7 @@ int wl1251_acx_fw_version(struct wl1251 > > } > > > > /* be careful with the buffer sizes */ > > - strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version))); > > - > > - /* > > - * if the firmware version string is exactly > > - * sizeof(rev->fw_version) long or fw_len is less than > > - * sizeof(rev->fw_version) it won't be null terminated > > - */ > > - buf[min(len, sizeof(rev->fw_version)) - 1] = '\0'; > > + strlcpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version))); > > > > ----------------------------------------------------------------- > > > > I think the comment is useful and should not be removed. > > I agree this comment is useful now that I'm taking a closer look, I > glanced at this too fast. > I'm not sure how to make coccinelle not remove comments between lines > though? Well, there is no such facility in Coccinelle to ignore comments. You can hack with other facilities provided in SmPL though ;) Try this: $ spatch -D patch --sp-file strlcopy.cocci --very-quiet drivers/net/wireless/ti/wl1251/acx.c --------------------------------------------------------------------- virtual patch @depends on patch@ expression dest, src, sz; identifier f; @@ ( - strncpy( + strlcpy( dest, src, sizeof(sz)); - dest[sizeof(sz) - 1] = '\0'; | - strncpy( + strlcpy( dest, src, f); - dest[f - 1] = '\0'; ) --------------------------------------------------------------------- This eliminates that case because expression is generic metavariable and it somehow matched whole "min(len, sizeof(...)..", so it better to divide the rules as done above to be more specific about the matching pattern. I thought to replace "identifier f" with "constant F" but that misses few cases. Also, it is advised to put a space affer '+/-' Thanks. -- Himanshu Jha Undergraduate Student Department of Electronics & Communication Guru Tegh Bahadur Institute of Technology