From: "Jiawen Wu" <jiawenwu@trustnetic.com>
To: "'Andrew Lunn'" <andrew@lunn.ch>,
"'Justin Stitt'" <justinstitt@google.com>
Cc: "'Mengyuan Lou'" <mengyuanlou@net-swift.com>,
"'David S. Miller'" <davem@davemloft.net>,
"'Eric Dumazet'" <edumazet@google.com>,
"'Jakub Kicinski'" <kuba@kernel.org>,
"'Paolo Abeni'" <pabeni@redhat.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-hardening@vger.kernel.org>
Subject: RE: [PATCH] net: txgbe: replace deprecated strncpy with strscpy
Date: Mon, 16 Oct 2023 11:05:29 +0800 [thread overview]
Message-ID: <002101d9ffdd$9ea59f90$dbf0deb0$@trustnetic.com> (raw)
In-Reply-To: <1c0e94ff-617b-4672-addb-8933f92edc29@lunn.ch>
On Sunday, October 15, 2023 12:31 AM, Andrew Lunn wrote:
> On Thu, Oct 12, 2023 at 09:20:04PM +0000, Justin Stitt wrote:
> > strncpy() is deprecated for use on NUL-terminated destination strings
> > [1] and as such we should prefer more robust and less ambiguous string
> > interfaces.
> >
> > Based on usage part_str usage within txgbe_read_pba_string(), we expect
> > part_str to be NUL-terminated but not necessarily NUL-padded:
> > | /* put a null character on the end of our string */
> > | pba_num[10] = '\0';
> >
> > Interestingly, part_str is not used after txgbe_read_pba_string():
> > | ...
> > | err = txgbe_read_pba_string(wx, part_str, TXGBE_PBANUM_LENGTH);
> > | if (err)
> > | strscpy(part_str, "Unknown", sizeof(part_str));
> > |
> > | netif_info(wx, probe, netdev, "%pM\n", netdev->dev_addr);
> > |
> > | return 0;
> > |
> > |err_remove_phy:
> > | txgbe_remove_phy(txgbe);
> > |err_release_hw:
> > | wx_clear_interrupt_scheme(wx);
> > | wx_control_hw(wx, false);
> > |err_free_mac_table:
> > | kfree(wx->mac_table);
> > |err_pci_release_regions:
> > | pci_release_selected_regions(pdev,
> > | pci_select_bars(pdev, IORESOURCE_MEM));
> > |err_pci_disable_dev:
> > | pci_disable_device(pdev);
> > | return err;
> > |}
> > ... this means this strncpy (or now strscpy) is probably useless. For
> > now, let's make the swap to strscpy() as I am not sure if this is truly
> > dead code or not.
>
> Hi Julian
>
> I agree, this looks like dead code.
>
> Jiawen, please could you submit a patch cleaning this up. Either swap
> to strscpy() and make use of the string, or delete it all.
Ah, I think I missed a line to print this string. I'm going to add it.
prev parent reply other threads:[~2023-10-16 3:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-12 21:20 [PATCH] net: txgbe: replace deprecated strncpy with strscpy Justin Stitt
2023-10-14 16:31 ` Andrew Lunn
2023-10-16 3:05 ` Jiawen Wu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='002101d9ffdd$9ea59f90$dbf0deb0$@trustnetic.com' \
--to=jiawenwu@trustnetic.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mengyuanlou@net-swift.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).