From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A799C43217 for ; Tue, 28 Sep 2021 13:33:41 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3374360F9D for ; Tue, 28 Sep 2021 13:33:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3374360F9D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3EC78339B; Tue, 28 Sep 2021 15:33:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MC+JyN/V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9885883316; Tue, 28 Sep 2021 15:32:53 +0200 (CEST) Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F3DD283347 for ; Tue, 28 Sep 2021 15:32:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rfried.dev@gmail.com Received: by mail-oi1-x233.google.com with SMTP id s69so29890211oie.13 for ; Tue, 28 Sep 2021 06:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=q3JFpf4MnEQrECimk5gErv/sVBCQ80PK4Mj33ukWl/Y=; b=MC+JyN/Vf/75YL+UiLAPly98cHJxST0+xyZ+4Jfmbm2gyhDy4m210A3rmtb6CKX9z6 tuiJ/iypASi0ym3gc4PImpI85J1HZMq20IurEW8xwAPrh5bLONOqAEQPzF225/EwIaJj 0TSAD+8XsGk8AWg55oLZCb7+SPdG8wU6ApFZyJLCZpPtTXPEbUhixzOIpwtUn9B9pgtR qC0PvRaeVdJqcXyDSGOL8YLZcRGWjhnMn9di3P/nuZZSCdVe+QLE37G/hbqlApQHUwUj s30NtFDednynz3FvuOcMTq8OoOn822B8ipHIUbekTXGjVR0B+yPy3Amzh7lgZTockPPO JdaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=q3JFpf4MnEQrECimk5gErv/sVBCQ80PK4Mj33ukWl/Y=; b=z6+Z7ZR7k98KoUPM0xWU0vk4e9/YYclKy7G64bNE7QVJFZCDjQ0rY8nbOafwTgkuKG 1k8SKzDqfkyFpQSS7hS328tT8K3zKTj+FMCNc//wJiCzMrkYRjppsaAC0muH/Fwjlcsf GZ0kGuUw2Gm2yD0RUJPrLRMP+GLOv/IcZK09uJOP2xS+S6X2/UDR4sOTZpcfrmDAAnrG wR2Uhc3IxKY/LNjMjaQkuP0T8FPpnjaDVaggZ7HajhSIFTDYQnu+r5PwMHgXhWCQ2cZj M6OJ2y2ly4T44wXKks8WSNY1Xqi+iP6Tz2Oy3zKPDwPU2Eu82u2QtVA+9bZ+NhbqEIHL efIw== X-Gm-Message-State: AOAM532YXgBOQtDCAg4mBlpq3xBeT5NwNJOQFB/7y5LiYKjN7XClC1S/ YQ7IMo6lSTawfmi7awHghjObnBwdLdMh6wNw0vEbkrXt7dMEdg== X-Google-Smtp-Source: ABdhPJzaN9L2bY5czZjq6mlGLBvAlPDXtZ4tuGzGMPvBZoyvS2f/U/xFAdAzt5ovh4gFWyyx784fiqFI6joJZt/Pkc8= X-Received: by 2002:a05:6808:bd1:: with SMTP id o17mr3702048oik.92.1632835947752; Tue, 28 Sep 2021 06:32:27 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-9-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-9-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:32:16 +0300 Message-ID: Subject: Re: [PATCH 08/25] net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN truncation To: Vladimir Oltean Cc: U-Boot Mailing List , Joe Hershberger Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Mon, Sep 27, 2021 at 2:22 PM Vladimir Oltean wrote: > > strncpy() simply bails out when copying a source string whose size > exceeds the destination string size, potentially leaving the destination > string unterminated. > > One possible way to address is to pass MDIO_NAME_LEN - 1 and a > previously zero-initialized destination string, but this is more > difficult to maintain. > > The chosen alternative is to use strlcpy(), which properly limits the > copy len in the (srclen >= size) case to "size - 1", and which is also > more efficient than the strncpy() byte-by-byte implementation by using > memcpy. The destination string returned by strlcpy() is always NULL > terminated. > > Signed-off-by: Vladimir Oltean > --- > drivers/net/fsl_enetc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c > index 566cdc7e546a..b7e2c1f0880c 100644 > --- a/drivers/net/fsl_enetc.c > +++ b/drivers/net/fsl_enetc.c > @@ -270,7 +270,7 @@ static void enetc_start_pcs(struct udevice *dev) > priv->imdio.read = enetc_mdio_read; > priv->imdio.write = enetc_mdio_write; > priv->imdio.priv = priv->port_regs + ENETC_PM_IMDIO_BASE; > - strncpy(priv->imdio.name, dev->name, MDIO_NAME_LEN); > + strlcpy(priv->imdio.name, dev->name, MDIO_NAME_LEN); > if (!miiphy_get_dev_by_name(priv->imdio.name)) > mdio_register(&priv->imdio); > } > -- > 2.25.1 > Reviewed-by: Ramon Fried