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 D507DC433FE for ; Tue, 28 Sep 2021 13:34:02 +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 5EA5460F9D for ; Tue, 28 Sep 2021 13:34:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5EA5460F9D 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 7747B833A4; Tue, 28 Sep 2021 15:33:40 +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="EKNYbKE0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E567083322; Tue, 28 Sep 2021 15:33:02 +0200 (CEST) Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) (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 D39948334F for ; Tue, 28 Sep 2021 15:32:34 +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-x32f.google.com with SMTP id x33-20020a9d37a4000000b0054733a85462so28923469otb.10 for ; Tue, 28 Sep 2021 06:32:34 -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=MU7Bwrqv1vBlSetooFoH3Gwoyg6QkzPs6APjwMAr6fU=; b=EKNYbKE0/NJdtk6OFi8Tue+qtx375jytrNNXzm69exE2m0JIPWSJFSqZjRooQ+iVI9 YRcunjqqWFxhWkmLbghOUT7w6jzb7dvEo7oDVlX9Csy5jSzt5wsjEspSKx+1oTOD+4kO qIGxJEKHFpN5soum/xdxrLWtTalfouFa6q8s+2nayTSH1G4VBhDT/XXbZPMkACzB443/ DotnN/50+aQsRxtMnKPYkmEXZqeJzThk5+V/7AVeG2uHx60xgD8gRfwYYtSl6UTi44aC R9IhwoZQ42YeQKYg2uYZ6Q7FfsGx4kYGK0ppBYX87o16yJq3Cjxq2zjuNbBCu9Xc6A1a A2pg== 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=MU7Bwrqv1vBlSetooFoH3Gwoyg6QkzPs6APjwMAr6fU=; b=PNdbaHDoSLvJY7lWTkmyE0ZgPEJtzX4ROyrquoRLkL2yk08SRukYxBi8HI+TSHELvU bzUbatfOS7hnGyN82VLqL5dXgnqcKjvGr98oQuQTD48lzcdmSObVpuiC6Cgl5ughLHkF uk4JHJtSQ51I7ucY6AuCQ4ISYQDxtVmm496FrqtlUAtoiBGi23TvffdZSDM9yf9pTYho A4b+gRLVwliLkUrdYAoXmAFFs24UK0wgfpJBHPs94zsjlXz2iDCdKHmHQJRE6ELF9AWg a8YAt0TS1rX3sH099cH1c2BgGAR1EzBJ4WWodlB9jT53e7IL2GCK2kI3nsViY3gnWHSc QI5Q== X-Gm-Message-State: AOAM530+Hf7eiZjaMsrnVDoix7ZOmDJS4WFeXyjRkWTCZVLjsKriiPcf qhTvFa5MuYIe8doGVTVZGE9mpoiwHUllPnpxBTxS2gOUllbjfA== X-Google-Smtp-Source: ABdhPJwEQhgyXpJHM8sCFJHB7vOhBPQZ4Pfk8f8/tpLoyAU05+DL/OIeshBWJM31qilcRMhlqrTAarSxuT+ek4zQmkw= X-Received: by 2002:a9d:7f8b:: with SMTP id t11mr5284861otp.363.1632835953646; Tue, 28 Sep 2021 06:32:33 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-10-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-10-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:32:22 +0300 Message-ID: Subject: Re: [PATCH 09/25] net: mcdmafec: ensure bus->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/fsl_mcdmafec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/fsl_mcdmafec.c b/drivers/net/fsl_mcdmafec.c > index c20aef4ab28d..e103f79305e7 100644 > --- a/drivers/net/fsl_mcdmafec.c > +++ b/drivers/net/fsl_mcdmafec.c > @@ -541,7 +541,7 @@ static int mcdmafec_probe(struct udevice *dev) > info->bus = mdio_alloc(); > if (!info->bus) > return -ENOMEM; > - strncpy(info->bus->name, dev->name, MDIO_NAME_LEN); > + strlcpy(info->bus->name, dev->name, MDIO_NAME_LEN); > info->bus->read = mcffec_miiphy_read; > info->bus->write = mcffec_miiphy_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried