lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD8XO3bezWoM7Pc0VoiFgoDWTLMN6VwV1vEFL7PR=_iohV82Ag@mail.gmail.com>
Date:   Thu, 4 Jun 2020 09:55:55 +0300
From:   Maxim Uvarov <maxim.uvarov@...aro.org>
To:     Joe Perches <joe@...ches.com>
Cc:     Kees Cook <keescook@...omium.org>,
        Andy Whitcroft <apw@...onical.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] checkpatch: Avoid missing typo suggestions

On Thu, 4 Jun 2020 at 03:39, Joe Perches <joe@...ches.com> wrote:
>
> On Wed, 2020-06-03 at 16:19 -0700, Kees Cook wrote:
> > My codespell dictionary has a lot of capitalized words. For example:
> >
> > MSDOS->MS-DOS
> >
> > Since checkpatch uses case-insensitive matching, I get an undefined
> > variable warning and then empty suggestions for things like this:
> >
> > Use of uninitialized value $typo_fix in concatenation (.) or string at ./scripts/checkpatch.pl line 2958.
> >
> > WARNING: 'msdos' may be misspelled - perhaps ''?
> > +       struct msdos_dir_entry *de;
> >
> > This fixes the matcher to avoid the warning, but it's still a rather
> > silly suggestion:
> >
> > WARNING: 'msdos' may be misspelled - perhaps 'MS-DOS'?
> > +       struct msdos_dir_entry *de;
> >
> > So I'm not really sure what to do with this ... filter out bad
> > suggestions instead?
>
> Hey Kees.
>
> Maybe this?
>
> btw: My codespell dictionary file moved to
> /usr/lib/python3/dist-packages/codespell_lib/data/dictionary.txt
>
> and I had to use --codespell --codespellfile=(above) so
> maybe there should be multiple lookups for this file
> like the array below.
>
> Are there other standard codespell dictionary locations?

It might be better to support standard and non standard locations. I
think it's better to request from codespell where his dictionary is.
I created ticket for this:
https://github.com/codespell-project/codespell/issues/1540

However this patch is good as a temporary solution.

Regards,
Maxim.

> ---
>  scripts/checkpatch.pl | 31 ++++++++++++++++++++++++++-----
>  1 file changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 5f00df2c3f59..52aa0dd53d80 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -59,7 +59,7 @@ my $minimum_perl_version = 5.10.0;
>  my $min_conf_desc_length = 4;
>  my $spelling_file = "$D/spelling.txt";
>  my $codespell = 0;
> -my $codespellfile = "/usr/share/codespell/dictionary.txt";
> +my $codespellfile;
>  my $conststructsfile = "$D/const_structs.checkpatch";
>  my $typedefsfile = "";
>  my $color = "auto";
> @@ -716,7 +716,20 @@ if (open(my $spelling, '<', $spelling_file)) {
>  }
>
>  if ($codespell) {
> -       if (open(my $spelling, '<', $codespellfile)) {
> +       if (!defined($codespellfile)) {
> +               my @csfiles = ("/usr/share/codespell/dictionary.txt",
> +                              "/usr/lib/python3/dist-packages/codespell_lib/data/dictionary.txt");
> +               foreach my $csfile (@csfiles) {
> +                       if (-f $csfile) {
> +                               $codespellfile = $csfile;
> +                               last;
> +                       }
> +               }
> +       }
> +
> +       if (!defined($codespellfile)) {
> +               warn "No codespell typos will be found - codespell dictionary not found\n";
> +       } elsif (open(my $spelling, '<', $codespellfile)) {
>                 while (<$spelling>) {
>                         my $line = $_;
>
> @@ -2963,13 +2976,21 @@ sub process {
>                         while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
>                                 my $typo = $1;
>                                 my $typo_fix = $spelling_fix{lc($typo)};
> -                               $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
> -                               $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
> +                               $typo_fix = $spelling_fix{$typo} if (!defined($typo_fix));
> +                               $typo_fix = $spelling_fix{uc($typo)} if (!defined($typo_fix));
> +                               $typo_fix = 'unknown typo fix' if (!defined($typo_fix));
> +                               if ($typo =~ /^[A-Z]+$/) {
> +                                       $typo_fix = uc($typo_fix);
> +                               } elsif ($typo =~ /^[A-Z]/) {
> +                                       $typo_fix = ucfirst($typo_fix);
> +                               }
> +
>                                 my $msg_level = \&WARN;
>                                 $msg_level = \&CHK if ($file);
>                                 if (&{$msg_level}("TYPO_SPELLING",
>                                                   "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
> -                                   $fix) {
> +                                   $fix &&
> +                                   $typo_fix ne 'unknown typo fix') {
>                                         $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
>                                 }
>                         }
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ