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 A07A2C4332F for ; Tue, 28 Sep 2021 13:32:29 +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 24ABB611CE for ; Tue, 28 Sep 2021 13:32:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 24ABB611CE 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 388C783328; Tue, 28 Sep 2021 15:32:24 +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="kB6tMO/i"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E11148326F; Tue, 28 Sep 2021 15:32:03 +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 E48DB83310 for ; Tue, 28 Sep 2021 15:31:54 +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 w206so30016969oiw.4 for ; Tue, 28 Sep 2021 06:31:54 -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=33Z6ugJsCtavi5C6UNE8AB/+0w/gHzw27fL/MRaNwSk=; b=kB6tMO/iKnQAanjyGL37WdSUL/chbztBbd4I2qk6/HnGnJPa9vtFJiNJemSzasLkPu XrX2AcR9QapDtreKnRyppfCB9D1KmN9p5CEM98HJER3Z8khuws+NRu8GhQex+IAZJHcc pJMr58hY2nWZ7lAPTAiogGbWvtTKHgK0IiEL39wZC0ua+QUyQ2SlgdN01fTpcTXoTNvB F80CPZtNgIya+FxQeMugS84h2zJHIiw6wghjudeQ74tDJVxSeb6okJW2+3sUvlE8Gn23 gj4z0raTkQIpqjUogSKHs6e6HCld7XZy1FMGgz5wu7wf+HsE6Q6bkhOp8q60/ZvvCrrm I1YQ== 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=33Z6ugJsCtavi5C6UNE8AB/+0w/gHzw27fL/MRaNwSk=; b=AfAAXqxv3DDRzY0DHGqjFTD0SQwOsEe2ce2hxZQXOYGuRAhg+NkVMeyK6zdYveccrA vkuyG61xM50e4EYas7KnDUGDJh8/P+Gxz6V534BK81hBrbtnLVi4a/andCsA7Du48sRS UbDDkep8Ca1W8AKTKqNgYS/6+p1Moeo5WmnRZbz7YBHi9GZshQGs6qtYQwn2YRInBR+B bdwxRv7u0JLvHh8YsxwHXcm/5lnmj3EPaXT80Y5nlYGH4MmNp92HGbtNIfNwaVQv4pt+ 6h92ZuTMsJs57EcIUwr/crhK8YZAzsHm1f+OrqUgFPVUeIh5Mt8N3SqJ6fsngrk/8qIA 8HTA== X-Gm-Message-State: AOAM530ma3yC/odKpNQO7UtGXFeCCChWIZ11Sa6v7QytXo/JQa9LzzvS 9m8QWQDt2J4TtkuMNjzrJugtkvNin83XdrX4cxs= X-Google-Smtp-Source: ABdhPJyUnLYLCS7B5vMo5HQ0GqzRnbue5uqDldHh/CSqwiNOgbRWvYZmL2PEZ4gOQcvWCsYsQXTqXbBXoH3qKqUC+7w= X-Received: by 2002:a54:4f1d:: with SMTP id e29mr3609324oiy.179.1632835913712; Tue, 28 Sep 2021 06:31:53 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-5-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-5-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:31:42 +0300 Message-ID: Subject: Re: [PATCH 04/25] net: at91_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/at91_emac.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/at91_emac.c b/drivers/net/at91_emac.c > index e40b94ad892d..b4581d8c9320 100644 > --- a/drivers/net/at91_emac.c > +++ b/drivers/net/at91_emac.c > @@ -507,7 +507,7 @@ int at91emac_register(struct bd_info *bis, unsigned long iobase) > 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 = at91emac_mii_read; > mdiodev->write = at91emac_mii_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried