All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Bulwahn <lukas.bulwahn@gmail.com>
To: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [Linux-kernel-mentees] [PATCH] checkpatch: add a new check for strcpy/strlcpy uses
Date: Tue, 5 Jan 2021 09:02:32 +0100	[thread overview]
Message-ID: <CAKXUXMy3XPsfUW80PyQR7KhYL=SOhncgdDzxmgZrOHQnZrfwVw@mail.gmail.com> (raw)
In-Reply-To: <20210104132536.38016-2-dwaipayanray1@gmail.com>

On Mon, Jan 4, 2021 at 2:25 PM Dwaipayan Ray <dwaipayanray1@gmail.com> wrote:
>
> strcpy() performs no bounds checking on the destination buffer.
> This could result in linear overflows beyond the end of the buffer.
>
> strlcpy() reads the entire source buffer first. This read
> may exceed the destination size limit. This can be both inefficient
> and lead to linear read overflows.
>
> The safe replacement to both of these is to use strscpy() instead.
> Add a new checkpatch warning which alerts the user on finding usage of
> strcpy() or strlcpy().
>
> Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
> ---

I remember Joe has already created a patch for that over Christmas
break; check lkml before sending this.

Other than that, looks good.

Lukas
>  scripts/checkpatch.pl | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index d6a4d25b0972..0003fd9de62c 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6604,6 +6604,13 @@ sub process {
>                         }
>                 }
>
> +# Check for strcpy/strlcpy uses
> +               if (defined($stat) &&
> +                   $stat =~ /^\+(?:.*?)\b(str[l]?cpy)\s*\(/) {
> +                       WARN("PREFER_STRSCPY",
> +                            "Prefer strscpy() over $1()\n" . "$here\n$stat\n");
> +               }
> +
>  # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
>  #              if ($perl_version_ok &&
>  #                  defined $stat &&
> --
> 2.27.0
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2021-01-05  8:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 13:25 [Linux-kernel-mentees] [PATCH] checkpatch: trivial style fixes Dwaipayan Ray
2021-01-04 13:25 ` [Linux-kernel-mentees] [PATCH] checkpatch: add a new check for strcpy/strlcpy uses Dwaipayan Ray
2021-01-05  8:02   ` Lukas Bulwahn [this message]
2021-01-05  8:19     ` Dwaipayan Ray
2021-01-05  8:58       ` Lukas Bulwahn
2021-01-05  8:04 ` [Linux-kernel-mentees] [PATCH] checkpatch: trivial style fixes Lukas Bulwahn
2021-01-05  8:41   ` Dwaipayan Ray
2021-01-08 15:09     ` Aditya
2021-01-05  8:23 [Linux-kernel-mentees] [PATCH] checkpatch: add a new check for strcpy/strlcpy uses Dwaipayan Ray
2021-01-05  8:44 ` Joe Perches
2021-01-05  8:59   ` Dwaipayan Ray
2021-01-05 10:20   ` David Laight

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='CAKXUXMy3XPsfUW80PyQR7KhYL=SOhncgdDzxmgZrOHQnZrfwVw@mail.gmail.com' \
    --to=lukas.bulwahn@gmail.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.