Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3707511pxt; Tue, 10 Aug 2021 09:29:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQqPfVkVzVIK6c/PSXUrwiWiuOjDSzLtim3sKNK9qu0R3gjXcXQQpqnnel1n7/SOCqn1/s X-Received: by 2002:a05:6402:1850:: with SMTP id v16mr2761555edy.308.1628612999658; Tue, 10 Aug 2021 09:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628612999; cv=none; d=google.com; s=arc-20160816; b=n+JQ4qmB14RSqW/QP6C+TNKzLm+fqrLgQ3mlylSZK2+m2tSpM1GuglTGQ1N1E+qI50 QVnOw2EHLLADrsDiAGxuxPBm7nFgYaVKxpE5mXSKQyjNZUS6M0PnnWAkgX5y7NWBn7cM iaV1y4RmLaVAsqlEEUzawo5YZy41+be1l1R8WFQUcXCNxCLChLTI9GkwkeMP0MXCJsUm OYG4nsLKpBfaizDPuGvcALAwRTV9pxdehOAqENsSnAqtHtA6uEb2lFsjJNjrmHbL9dGB JymXZqztQ8keuc4ygQ1ewImq6b5UFsz2OP2ZhDUndXor5A+xRzsZsmzmmgC6PKIdCVQc dbtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=A0RKRD6fr2UNDn7sajsm3RKAKeUrFbZHlIHwSi9SBx4=; b=Fa5bAQlOw1JDosuW/QKGEP/btyuOxBSC6bokKJt7l0Sx0NTxgCIMIZ/Yb6uDbJGSfO hHZw4/l1LsMF2mjuIeOsiBqT/NFFwBfF+2bIeJ10tdoffIRbDIvsjwlf73bRAa4o456i T/DhOnPQVmWdYs1lJSNxfRASfzEd0MaDqcBnFbJKILolzqwG7iQ9NdW3a7wBCXrHXfYf 3rD5AP+NpPVheR3jDnxhEZhyCmfOCrypk4fFUiUZKMs0eJYr2TGDeQL1PE3HBDf818Hp 9IIO+QJmz+VXGJBRN90ypqppK0nungpY94Z5axrqPWCCAyG4iOpmh7zX+NMaDOqYF6jy kg3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OMXMZnlj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id cf27si7291051edb.374.2021.08.10.09.29.34; Tue, 10 Aug 2021 09:29:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OMXMZnlj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240366AbhHJMHk (ORCPT + 99 others); Tue, 10 Aug 2021 08:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238600AbhHJMHi (ORCPT ); Tue, 10 Aug 2021 08:07:38 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AB7C0613D3; Tue, 10 Aug 2021 05:07:16 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id b7so893124plh.7; Tue, 10 Aug 2021 05:07:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A0RKRD6fr2UNDn7sajsm3RKAKeUrFbZHlIHwSi9SBx4=; b=OMXMZnlj/gmJQz3eVxlqdJeX/11ldBtNMyq3zZN8Lq5SAArpcUGW6C7VTF41Fy64Jd 5ZJATUAHV6ziTC2lqPAn4e/z8tfki9SjlNRs9fPp3b76fGcMe6KyAXc8DURb1lYzcK+F IXGv8pNrxFdie2ueeVVHXYWhvaCJkTBGx0sBtS3HIu8zoT46cIyMb6HSSTqnQCMXjEjS YiZUl1MoVIxzU8UCBG7Q9KBpiRAPq+y8obALrcCmbhLulzqZ2AtKlQQ3OH+wKKbi9lJA ntj19duqW5Ey3WwZGm3jsmQsIc3whTMI5tuCLcdIawWSDoONzurnlNZi5aN5+WaeVeQB fURg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A0RKRD6fr2UNDn7sajsm3RKAKeUrFbZHlIHwSi9SBx4=; b=DSNfvyjU92tO/LPB8t4Bb9dZMwsFvUavxGc0FstZtYO4WYdm7FoBr0ySvj1Hy7c+z+ UEmV2yMSFhitzYHxpjHCHKhLTKfOJrxhcehDHIMkFMXPm+9LW7HzDXhxQYJRORFzzaLM AIxRPUvGzTTUs8yjIAVKIqiuDQ18Ypq1nhRPAattvEZO3WEb47vbXfigZOzW65j63lx2 XV8sJGv/WMjaErPwD0I/sifsRLbZIhHpHCO/2CHO7Vtox5/ZbLXvP+yyDV267nRJ1NDt APrHhak8EOkWDtw2cp7oua0+kxn6mBqqs6UPA6b0ZYwuP4B3YaN0kz4tJTbdTVEhMbA1 By5A== X-Gm-Message-State: AOAM532nU7zMTkxXzyaP07ixT8oxx2dZRQL1HgJFzzQwB/hJiZp3iP7E SRBP6eFChWXX2f0SXEoeMulUv2QAAwhHypKWrgs= X-Received: by 2002:a63:40c1:: with SMTP id n184mr1180502pga.74.1628597236251; Tue, 10 Aug 2021 05:07:16 -0700 (PDT) MIME-Version: 1.0 References: <20210807152225.9403-1-len.baker@gmx.com> <20210808172503.5187cd24@jic23-huawei> <20210809102131.000021eb@Huawei.com> <20210809161422.GA2619@titan> In-Reply-To: <20210809161422.GA2619@titan> From: Andy Shevchenko Date: Tue, 10 Aug 2021 15:06:39 +0300 Message-ID: Subject: Re: [PATCH v2] drivers/iio: Remove all strcpy() uses in favor of strscpy() To: Len Baker Cc: Jonathan Cameron , Lars-Peter Clausen , Kees Cook , linux-hardening@vger.kernel.org, linux-iio , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 9, 2021 at 7:14 PM Len Baker wrote: > On Mon, Aug 09, 2021 at 10:21:31AM +0100, Jonathan Cameron wrote: > > On Sun, 8 Aug 2021 22:00:34 +0300 > > Andy Shevchenko wrote: > > > On Sun, Aug 8, 2021 at 7:25 PM Jonathan Cameron wrote: > > > > On Sat, 7 Aug 2021 17:22:25 +0200 > > > > Len Baker wrote: ... > > > Isn't it too early? Or am I missing something (see below)? > > > > > /* use length + 2 for adding minus sign if needed */ > > > > > - str = devm_kzalloc(regmap_get_device(st->map), > > > > > - strlen(orient) + 2, GFP_KERNEL); > > > > > + n = strlen(orient) + 2; > > > > > + str = devm_kzalloc(regmap_get_device(st->map), n, > > > > > + GFP_KERNEL); > > > > > if (str == NULL) > > > > > return -ENOMEM; > > > > > if (strcmp(orient, "0") == 0) { > > > > > - strcpy(str, orient); > > > > > + strscpy(str, orient, n); > > > > > } else if (orient[0] == '-') { > > > > > - strcpy(str, &orient[1]); > > > > > + strscpy(str, &orient[1], n); > > > > > } else { > > > > > str[0] = '-'; > > > > > - strcpy(&str[1], orient); > > > > > + strscpy(&str[1], orient, n - 1); Even if we leave the logic as is, this might be better if (orient[0] == '-') str = devm_kstrdup(dev, orient + 1, GFP_KERNEL); else if (orient[0] != '0' || orient[1] != '\0') str = devm_kasprintf(dev, GFP_KERNEL, "-%s", orient); else str = devm_kstrdup(dev, orient, GFP_KERNEL); if (!str) return -ENOMEM; -- With Best Regards, Andy Shevchenko