comparison libtommath/helper.pl @ 1655:f52919ffd3b1

update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79) * make key-generation compliant to FIPS 186.4 * fix includes in tommath_class.h * update fuzzcorpus instead of error-out * fixup fuzzing make-targets * update Makefile.in * apply necessary patches to ltm sources * clean-up not required ltm files * update to vanilla ltm 1.1.0 this already only contains the required files * remove set/get double
author Steffen Jaeckel <s_jaeckel@gmx.de>
date Mon, 16 Sep 2019 15:50:38 +0200
parents
children 1051e4eea25a
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use Getopt::Long;
7 use File::Find 'find';
8 use File::Basename 'basename';
9 use File::Glob 'bsd_glob';
10
11 sub read_file {
12 my $f = shift;
13 open my $fh, "<", $f or die "FATAL: read_rawfile() cannot open file '$f': $!";
14 binmode $fh;
15 return do { local $/; <$fh> };
16 }
17
18 sub write_file {
19 my ($f, $data) = @_;
20 die "FATAL: write_file() no data" unless defined $data;
21 open my $fh, ">", $f or die "FATAL: write_file() cannot open file '$f': $!";
22 binmode $fh;
23 print $fh $data or die "FATAL: write_file() cannot write to '$f': $!";
24 close $fh or die "FATAL: write_file() cannot close '$f': $!";
25 return;
26 }
27
28 sub check_source {
29 my @all_files = (
30 bsd_glob("makefile*"),
31 bsd_glob("*.{h,c,sh,pl}"),
32 bsd_glob("*/*.{h,c,sh,pl}"),
33 );
34
35 my $fails = 0;
36 for my $file (sort @all_files) {
37 my $troubles = {};
38 my $lineno = 1;
39 my $content = read_file($file);
40 push @{$troubles->{crlf_line_end}}, '?' if $content =~ /\r/;
41 for my $l (split /\n/, $content) {
42 push @{$troubles->{merge_conflict}}, $lineno if $l =~ /^(<<<<<<<|=======|>>>>>>>)([^<=>]|$)/;
43 push @{$troubles->{trailing_space}}, $lineno if $l =~ / $/;
44 push @{$troubles->{tab}}, $lineno if $l =~ /\t/ && basename($file) !~ /^makefile/i;
45 push @{$troubles->{non_ascii_char}}, $lineno if $l =~ /[^[:ascii:]]/;
46 push @{$troubles->{cpp_comment}}, $lineno if $file =~ /\.(c|h)$/ && ($l =~ /\s\/\// || $l =~ /\/\/\s/);
47 # we prefer using XMALLOC, XFREE, XREALLOC, XCALLOC ...
48 push @{$troubles->{unwanted_malloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmalloc\s*\(/;
49 push @{$troubles->{unwanted_realloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\brealloc\s*\(/;
50 push @{$troubles->{unwanted_calloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bcalloc\s*\(/;
51 push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bfree\s*\(/;
52 # and we probably want to also avoid the following
53 push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/;
54 push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemset\s*\(/;
55 push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/;
56 push @{$troubles->{unwanted_memmove}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemmove\s*\(/;
57 push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcmp\s*\(/;
58 push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcmp\s*\(/;
59 push @{$troubles->{unwanted_strcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcpy\s*\(/;
60 push @{$troubles->{unwanted_strncpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrncpy\s*\(/;
61 push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bclock\s*\(/;
62 push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bqsort\s*\(/;