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 B7C23C4321E for ; Tue, 28 Sep 2021 13:33:28 +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 3810660FE8 for ; Tue, 28 Sep 2021 13:33:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3810660FE8 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 8EE7D83383; Tue, 28 Sep 2021 15:33:20 +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="UoM2hs/5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D41283321; Tue, 28 Sep 2021 15:32:39 +0200 (CEST) Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) (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 C21DE8331C for ; Tue, 28 Sep 2021 15:32:21 +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-x330.google.com with SMTP id 77-20020a9d0ed3000000b00546e10e6699so28983501otj.2 for ; Tue, 28 Sep 2021 06:32:21 -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=Ig5dJ5dVV4nOdzfhCUffXupmSi9gCQTdPzhxT8Z/v3w=; b=UoM2hs/5WxPFzXgxcGw6COPSTBxZb6vhoMtLN/qfmt+6IX09LVfOAS4sP5q1hoYEDS F0ZIyIfOxwgjtu8V04OKveo4unmO+75J+Bo87kCxYqxJK9Q6KXOHaICOAObFoFCK5YW/ RzD9fKNW7WgDWvHcNO20RxTyJqEVE3ZMsg61b2/tlZvVcIHAoJzBqE8jTyPKuoTC8dHS s+KFQZSplBNGANP1kkVvKtD4pV7eb2/HWTUMfBSG+eABYCSOg7p3gvKq613qKp1ORBFu vlSO3GVLuOZ4AUIQVjSCA8cZAzFsbzhHsm+DzdUU2YF4R6xoD2DBQGWdyHI21yDAxDxi 94SA== 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=Ig5dJ5dVV4nOdzfhCUffXupmSi9gCQTdPzhxT8Z/v3w=; b=JWcjnu6pI5dM8yHahLzKDmfLgfYgzhjkgJGvF/sXZz8KWAy1JM97sZmuoulzRw104b Mh07bQTT1xIZKi3HbjMH7xx/w+h7SiQu85yfr5OZzU0rrQvyHiGYtW9a94P5+17lIhmO dopJN03yKZpSiGNxvn+qrrwpY6mayBMl7dHOimW+UHfrfTDg80VEJ3C4iWgiTm0iqPfc c7jnD8eMtoUXEeTUkUMjFWh8CD06vhBfCbRawmwLjIt+J/x12JHMhzHjg2UzTQQXOOGq 0AgBN18s1e5rM9WLQidcxuGk64Zhw5X5MD34Z1N1cUXsBehzE0EHDRd2x8rW2mtiR2vd rdww== X-Gm-Message-State: AOAM530RFUdr9Uej5hs/EGXhibwbFAPQ/RvwF2tvCCRRJ1sK9OQTqWnJ F+PXFKzkj3pA1KPFHF5nu60Id0e+kZBOYjejF1k= X-Google-Smtp-Source: ABdhPJzvaHxFNSnc8KNd1uWXRfqh+w7/ai9uhA8rE4DWhEJMX1GH8wNg1fyNF+1SGk43RVacR26n7Hy09Ocok+DAQKY= X-Received: by 2002:a05:6830:1557:: with SMTP id l23mr5238077otp.154.1632835940466; Tue, 28 Sep 2021 06:32:20 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-8-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-8-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:32:09 +0300 Message-ID: Subject: Re: [PATCH 07/25] net: ep93xx: 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/ep93xx_eth.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ep93xx_eth.c b/drivers/net/ep93xx_eth.c > index 0218349b0450..9f8df7de0609 100644 > --- a/drivers/net/ep93xx_eth.c > +++ b/drivers/net/ep93xx_eth.c > @@ -427,7 +427,7 @@ int ep93xx_miiphy_initialize(struct bd_info * const bd) > struct mii_dev *mdiodev = mdio_alloc(); > if (!mdiodev) > return -ENOMEM; > - strncpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN); > + strlcpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN); > mdiodev->read = ep93xx_miiphy_read; > mdiodev->write = ep93xx_miiphy_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried