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 34C66C433EF for ; Tue, 28 Sep 2021 13:35:47 +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 9F01B60FC2 for ; Tue, 28 Sep 2021 13:35:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9F01B60FC2 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 F29C4832FE; Tue, 28 Sep 2021 15:34:51 +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="Bwransr+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ECBC7833AE; Tue, 28 Sep 2021 15:33:52 +0200 (CEST) Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) (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 C827F8332E for ; Tue, 28 Sep 2021 15:33:06 +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-oo1-xc2f.google.com with SMTP id h11-20020a4aa74b000000b002a933d156cbso7156690oom.4 for ; Tue, 28 Sep 2021 06:33:06 -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=OdXnu5QsvZ4NCWyIqf4HBMfq9v0g3dl4Ysr6i+Vjiew=; b=Bwransr+N4BgOMq9dY8mU355Q0bGETNkBOWtPfOXcP9tkJhl+4UOvLbr0QkkjeS01l etrw0XGf1nWWasIOr1TQQagAFMCs9cdjOArYs2jrcNvxNfCAoZKPAJIfcyXkBbI8ALCY fTjFF0bxd57LSe9lKjez1PQIyCfEKTql167wneEzsD9VIE6yYTINEtBzvXIA6lM4Vt4r TMgimP5811qPknILcVhrgXkA+h5vO85X8+vxSiXWBjYqVEUTpalpAGyN8rFiRd69VL9z hWrPgn51WEwBC+6sPZP3v6/b3s5Z7V4hrsObOI1QxEtglg1eeD1f2V1l5Wj5FBNYYaza 2cUw== 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=OdXnu5QsvZ4NCWyIqf4HBMfq9v0g3dl4Ysr6i+Vjiew=; b=DTAH+usxafqKupsXSGKBGUvkYHAqzlzdQw2LKgk4Ivxb12qsRaPhSG35u6YNExxzQM n/hqwqRLDDijo7+f2+EjmIziZL/cSEcMID8cMeO3C9WQ4FpUGecA0VreLpyu8lRMDynd 5a2k2n+ZS4oWwKqbPfXKeUbsKWQmX2KM9fHBBLkYktA4SatVANE8X3NJQEOureSiEtUD jWZNvf9gu8B1Kc53B0NNMtZDPN16DchU1kDmeJ8lpKIc21UE9f+N7yIA3HKCtgaT9xHJ hQ54GVehBPyZwFHghwk/9VoR8dJjPASbDDQ/GJhBsShIvl0Q+yLwyZtMPu09VhkF4uLD x8NQ== X-Gm-Message-State: AOAM53118vjhGqEzaRf160bHX/8xCc8pTro4ods//5fOO/XjhBJam/5e vE8sXYuamRdL8N2N2Tgh2uBIYpyNDkOu7bT8Y38= X-Google-Smtp-Source: ABdhPJzcmRQzqdi+vgc4SV1Zf7ryWH2qPe6udnFXQXUV3pQMkmCgg4WBnLxi3Zi/iQBgfyMRf17e1Jl75fXUW86VdHg= X-Received: by 2002:a4a:b543:: with SMTP id s3mr4929473ooo.94.1632835985609; Tue, 28 Sep 2021 06:33:05 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-14-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-14-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:32:54 +0300 Message-ID: Subject: Re: [PATCH 13/25] net: mpc8xx_fec: 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/mpc8xx_fec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/mpc8xx_fec.c b/drivers/net/mpc8xx_fec.c > index 282c2599d3c4..4eb826028111 100644 > --- a/drivers/net/mpc8xx_fec.c > +++ b/drivers/net/mpc8xx_fec.c > @@ -160,7 +160,7 @@ int fec_initialize(struct bd_info *bis) > struct mii_dev *mdiodev = mdio_alloc(); > if (!mdiodev) > return -ENOMEM; > - strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN); > + strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN); > mdiodev->read = fec8xx_miiphy_read; > mdiodev->write = fec8xx_miiphy_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried