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 3AC77C433EF for ; Tue, 28 Sep 2021 13:37:00 +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 BE7EB60FC0 for ; Tue, 28 Sep 2021 13:36:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BE7EB60FC0 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 1860D83361; Tue, 28 Sep 2021 15:36:08 +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="Y6d6a+gr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D3CF38332D; Tue, 28 Sep 2021 15:35:16 +0200 (CEST) Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) (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 C83478338B for ; Tue, 28 Sep 2021 15:33:42 +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-x22e.google.com with SMTP id e24so20063387oig.11 for ; Tue, 28 Sep 2021 06:33:42 -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=kJ+xF9at6qB8kSBiRrRzs/98cWVSJR/mYyk8KbWnBJ4=; b=Y6d6a+gr6IFRrTilfWm02umSoOe5WaHA/KNz81JX7C9/fWVjevs2XA07VpstSpHCeZ cCyf9groervnmpGk9oxD1BEe1k/Q/NyznxfBgR5gDyYsvKBZPlGQ5luUDeHOLnFWqvGq 9Gpit7ipPnu6K765t0ovja25vnyKMbRFq1aWWptLYXK3+SobdSLC5N3iWpi2B4xzxsXl eoNRBYWA3doBPaug8REeA2SIPPTrnzjyOGJLjeLYzn0RbcIcGFuTa7O7y8SoSZ6ju6eG S2Vebpf3oUvYpZ5Alb4zIV9H9Sh5X173DiFQNwwbsZ9ShkFQQJdaEzL0aotkSXBmstKG 4WYg== 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=kJ+xF9at6qB8kSBiRrRzs/98cWVSJR/mYyk8KbWnBJ4=; b=TzaPegCbFh4kZCY4LPwghcVxStQ4ycIdaxNZjTBMOgNQQZpZGPQ6CWKsYhX/0bUffG GvrtsnZEevxVwwbjE8T7ayMwZ64K7wWh/wNbLkme4BZkbW7Gm/VtLTR/jp1/E6lLjnUX HG25De2TpvkrMPIMMZ+r64VYtKtJ5NDJV8L4n104hkHw+O/WPauPgcQmgz/TedWHoEzB t6wl8JRcsb7N8v4Blg4zV+uMblLp8FRgpkzQ3PGjq4a+147jr/IjAxNUIl7+zSyiIuIf E7rFIOiRtEisTYIGXumQFklFU1KdPZRYLMVskIYMjRw8M0ApMnnF5LYIIfgeo6NpKTWu ryAw== X-Gm-Message-State: AOAM53136+ktZxmc3q08BUduNXfiuJ2KB2nLfI6UsXFOgaNXFvBMoXRw bFoG5HvYkEdMrk0SYCuS6T8wF0i6/o6YnF0TGDk= X-Google-Smtp-Source: ABdhPJyNKO+V+7rKEkmeMS67Pp1IybbI99kfdhR39iQBG3CsYF9pKcVyPl0qGrHMz80Bqg65TuhYB8yj1JzeGqWuel0= X-Received: by 2002:a05:6808:c4:: with SMTP id t4mr3562954oic.22.1632836019922; Tue, 28 Sep 2021 06:33:39 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-19-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-19-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:33:28 +0300 Message-ID: Subject: Re: [PATCH 18/25] net: davinci_emac: 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/ti/davinci_emac.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ti/davinci_emac.c b/drivers/net/ti/davinci_emac.c > index bfe1b84cd566..2dfadbd82d5b 100644 > --- a/drivers/net/ti/davinci_emac.c > +++ b/drivers/net/ti/davinci_emac.c > @@ -816,7 +816,7 @@ static int davinci_emac_probe(struct udevice *dev) > struct mii_dev *mdiodev = mdio_alloc(); > if (!mdiodev) > return -ENOMEM; > - strncpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN); > + strlcpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN); > mdiodev->read = davinci_mii_phy_read; > mdiodev->write = davinci_mii_phy_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried