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 67078C433EF for ; Tue, 28 Sep 2021 13:36:30 +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 E814660FC0 for ; Tue, 28 Sep 2021 13:36:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E814660FC0 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 304CB831A0; Tue, 28 Sep 2021 15:35:52 +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="AGENzQVB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BEF783363; Tue, 28 Sep 2021 15:34:29 +0200 (CEST) Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) (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 EF0F983377 for ; Tue, 28 Sep 2021 15:33:25 +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-ot1-x336.google.com with SMTP id c26-20020a056830349a00b0054d96d25c1eso2435511otu.9 for ; Tue, 28 Sep 2021 06:33:25 -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=M6/isJ0+rwv8eaJD3nGxZHOXMa0NTLjb43X93aLzjnI=; b=AGENzQVBRDbeefXB5U+3VuRzfmlIbQ07xeu20yoRb7V+WKZ9zoPzxjW0nnL8JZgQaR Wep8vWDK/uciBQvFg94BIdfOIrpn3EEovuFsfGSl2CpLEHvYcQ+qHfrk+nENOvS9RFkk lt5L1+yHqvaWuXDjLjwcVyw9fcT5D+BvUMCM6dakYu6SNN/rW1cnLWW2E1ezC+he1tLs +thXcjGT7XSQMTdu8LI4DBzVDlNYSuZu8H/o9DGmVeZ95c+StcjPh/jqYldu+vvL+q+x Z81fiJ20YDAmiUH/8oByuHL2JrwwWP8RHaEbl1OveUfRJg3cWqyLoYW6TPq0mX4Li82l sfaQ== 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=M6/isJ0+rwv8eaJD3nGxZHOXMa0NTLjb43X93aLzjnI=; b=8JVPKT/PvxXwVY5j+v412JXrDuhY3mfdDFSLOcT6QGe1tln8CXaOyDKxEYhtzQPAvH JWFNfVCte/0ovMTmU3BSrGkb0mg5biYeNZBDRSFT/GV8dL7sdkas0NXyMCWHlMopULBz ApWDQEL7E3crcRlI9OTkHBG1Lk0kPzjfsYGQhPt06XLUPmJWNaBfG22ZZuvgDFVvr8c6 DZsRHLhobW4/bjlj6P7qITWcPBcaJKTVeNsJ5MPyg/03+5tCP3/s73/iQJDMylainZjN mzlKSa4M2PRRdZymjKOQWWXTj9W9DoiAYhYZszpHbeh/iANlaYTEslXWF7DkHwJj5tgq A2mQ== X-Gm-Message-State: AOAM531tHWTbhNQd4yEjLl/7H+X5QngYOv45uGd1uQO9jCrAm3XrLxdd TF1AfCGH2bvmURRY4vIFx0HZT3JNSsr4H/HSwIk= X-Google-Smtp-Source: ABdhPJxxy3+yI+vl+kZXc3N9XlCVgR+JUsDxh9WJ1EfsvB5na/vq3hXSncB/959mIyi9ci+0ewe+TSjGj3BYwdibX8g= X-Received: by 2002:a05:6830:1557:: with SMTP id l23mr5243715otp.154.1632836004660; Tue, 28 Sep 2021 06:33:24 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-18-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-18-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:33:13 +0300 Message-ID: Subject: Re: [PATCH 17/25] net: smc911x: ensure mdiodev->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/smc911x.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c > index 8f420261fa8d..5d9a73f23d75 100644 > --- a/drivers/net/smc911x.c > +++ b/drivers/net/smc911x.c > @@ -425,7 +425,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv) > if (!mdiodev) > return -ENOMEM; > > - strncpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN); > + strlcpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN); > mdiodev->read = smc911x_miiphy_read; > mdiodev->write = smc911x_miiphy_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried