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 E07ECC433EF for ; Tue, 28 Sep 2021 13:32:16 +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 652A461266 for ; Tue, 28 Sep 2021 13:32:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 652A461266 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 1256683325; Tue, 28 Sep 2021 15:32:14 +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="K36yzqWx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 51BCC8330B; Tue, 28 Sep 2021 15:31:55 +0200 (CEST) Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (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 3C421832FC for ; Tue, 28 Sep 2021 15:31:48 +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-x334.google.com with SMTP id o59-20020a9d2241000000b0054745f28c69so26859121ota.13 for ; Tue, 28 Sep 2021 06:31:48 -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=ickXy8uzhVRWY3apAFZk0+ELnlxvO/Xe+Ag97FFzFgo=; b=K36yzqWxFOLwJw4s9VM0tlwDPXPkVUDE9tOoWoWFh45N8yC1ji07epQzfRvyiNp1Jq nVZBvZcZnfdqmfmnBtnREX57YXU7EV6e8ZwgJO3/dfMvFnb5HtbjW+6lANenM2zMot96 2dFy22Q5xSC9n9H4uckEXdp2q/ItSx/gzvXLJdZzaMOK36ELmTkWtMQOG7rAGnIBGh2D nd3HDgrpb0vOgszEmaocpjXB6fGQoiVfQDEtkFj9P/qa35THT7Vqg9Zs3Y2oCO3icPl6 vdIoBccr6KT8X+EnP6NwxApJW6PmFJjaojtZ3u6hxQVK+aesCBRm/ksB57zZxk6Z5lkc FnJw== 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=ickXy8uzhVRWY3apAFZk0+ELnlxvO/Xe+Ag97FFzFgo=; b=wKXI2TBUaYxY4Hbr+RaC7QjEP0h+gaAAsjRYEoUEJsgfTVLgDwys7/ELYcVDcdrXLM k7qJyiyalhTYU+k3xiBDSuPKb2mfs/DMfE9cP/qcRjSn71uK/jKYEqtG61QAQeDGORq9 yX5OZ3iFceMtZWqsVxZXF0dllwB5GgS3nhzTzxvTkSTwPbAB2nE4OBGvT+B8Gk/RcKgR YHybY1/pr5Ioi/OBXF4USRto8my1yX4uqp+OmsOpFzJF35OuYbe1C8Hnin1RpwWSOWVY l8ynQA+VF7uu2sMQJhyTu5vN9Rl6xLUMm517Z/TK8tJyCFBwYB3K6c/k37h22tq54S33 //Xw== X-Gm-Message-State: AOAM532shO1rns03OKWPm+R7wMqjSj3EHsWQfiEJMFBiqg6QFug6zLjC ZUSLxPbPdFf4ImyZ2nVeVTVMHS7BeRS6hPX5rxYXelKBPsuJSA== X-Google-Smtp-Source: ABdhPJx1/Cfx1jFFAUVfOkseJtZfeddx0wkdRXWuEB858pezr+KU5JRGfvlmS2yHoRXjFz981I1Rmo4OzFN3ARsmt/Q= X-Received: by 2002:a05:6830:1557:: with SMTP id l23mr5235166otp.154.1632835906997; Tue, 28 Sep 2021 06:31:46 -0700 (PDT) MIME-Version: 1.0 References: <20210927112205.301876-1-vladimir.oltean@nxp.com> <20210927112205.301876-4-vladimir.oltean@nxp.com> In-Reply-To: <20210927112205.301876-4-vladimir.oltean@nxp.com> From: Ramon Fried Date: Tue, 28 Sep 2021 16:31:35 +0300 Message-ID: Subject: Re: [PATCH 03/25] net: armada100_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/armada100_fec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/armada100_fec.c b/drivers/net/armada100_fec.c > index 018891e173c3..5d4b90c6ba72 100644 > --- a/drivers/net/armada100_fec.c > +++ b/drivers/net/armada100_fec.c > @@ -717,7 +717,7 @@ int armada100_fec_register(unsigned long base_addr) > 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 = smi_reg_read; > mdiodev->write = smi_reg_write; > > -- > 2.25.1 > Reviewed-by: Ramon Fried