public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Ethan Carter Edwards <ethan@ethancedwards.com>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] ext4: replace strcpy() with strscpy() in ext4_init_dot_dotdot()
Date: Sun, 18 May 2025 23:26:42 -0400	[thread overview]
Message-ID: <20250519032642.GB158804@mit.edu> (raw)
In-Reply-To: <20250518-ext4-strcpy-v1-1-6c8a82ff078f@ethancedwards.com>

On Sun, May 18, 2025 at 12:48:50PM -0400, Ethan Carter Edwards wrote:
> strcpy() is deprecated; use strscpy() instead.

We never actually needed to use strcpy here, actually, becase de->name
is not NUL-terminated.  Instead, we have de->name_len which tells us
how many characters are in a directory entry's name.

So we could just as easily replace:

	strcpy(de->name, ".")

with

	de->name[0] = '.'


and

	strcpy(de->name, ".")
with

	de->name[0] = de->name[1] = '.'

.... if you really want to get rid of the evil strcpy call.  As it
turns out, it's super easy to assure oneself of why what's currently
there is safe, but you really want it to go away for religious reasons
then you might as well do it in a more performant way.

Also note that there is a similar use of strcpy() in fs/ext4/inline.c.
If you really want to "fix" things in fs/ext4/inode.c, you might as
well fix it in all of sources files in fs/ext4.

Cheeres,

					- Ted

      reply	other threads:[~2025-05-19  3:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-18 16:48 [PATCH] ext4: replace strcpy() with strscpy() in ext4_init_dot_dotdot() Ethan Carter Edwards
2025-05-19  3:26 ` Theodore Ts'o [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=20250519032642.GB158804@mit.edu \
    --to=tytso@mit.edu \
    --cc=adilger.kernel@dilger.ca \
    --cc=ethan@ethancedwards.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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