2 # Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
9 # This is just a quick script to scan for cases where the 'error'
10 # function name in a XXXerr() macro is wrong.
12 # Run in the top level by going
13 # perl util/ck_errf.pl */*.c */*/*.c
27 mkerr.pl [options] [files...]
31 -conf FILE Use the named config file FILE instead of the default.
33 -debug Verbose output debugging on stderr.
35 -internal Generate code that is to be built as part of OpenSSL itself.
36 Also scans internal list of files.
38 -strict If any error was found, fail with exit code 1, otherwise 0.
40 -help Show this help text.
42 ... Additional arguments are added to the file list to scan,
43 if '-internal' was NOT specified on the command line.
50 last unless $arg =~ /-.*/;
51 $arg = $1 if $arg =~ /-(-.*)/;
52 if ( $arg eq "-conf" ) {
55 } elsif ( $arg eq "-debug" ) {
57 } elsif ( $arg eq "-internal" ) {
59 } elsif ( $arg eq "-strict" ) {
61 } elsif ( $arg =~ /-*h(elp)?/ ) {
64 } elsif ( $arg =~ /-.*/ ) {
65 die "Unknown option $arg; use -h for help.\n";
72 die "Extra parameters given.\n" if @ARGV;
73 $config = "crypto/err/openssl.ec" unless defined $config;
74 @source = ( glob('crypto/*.c'), glob('crypto/*/*.c'),
75 glob('ssl/*.c'), glob('ssl/*/*.c') );
77 die "Configuration file not given.\nSee '$0 -help' for information\n"
78 unless defined $config;
82 # To detect if there is any error generation for a libcrypto/libssl libs
83 # we don't know, we need to find out what libs we do know. That list is
84 # readily available in crypto/err/openssl.ec, in form of lines starting
85 # with "L ". Note that we always rely on the modules SYS and ERR to be
86 # generally available.
87 my %libs = ( SYS => 1, ERR => 1 );
88 open my $cfh, $config or die "Trying to read $config: $!\n";
90 s|\R$||; # Better chomp
91 next unless m|^L ([0-9A-Z_]+)\s|;
97 foreach my $file (@source) {
98 open( IN, "<$file" ) || die "Can't open $file, $!";
101 if ( !/;$/ && /^\**([a-zA-Z_].*[\s*])?([A-Za-z_0-9]+)\(.*([),]|$)/ ) {
102 /^([^()]*(\([^()]*\)[^()]*)*)\(/;
103 $1 =~ /([A-Za-z_0-9]*)$/;
105 $func =~ tr/A-Z/a-z/;
107 if ( /([A-Z0-9_]+[A-Z0-9])err\(([^,]+)/ && !/ckerr_ignore/ ) {
111 unless ( $libs{$errlib} ) {
112 print "$file:$.:$errlib not listed in $config\n";
113 $libs{$errlib} = 1; # To not display it again
118 print "$file:$.:???:$n\n";
123 if ( $n !~ /^(.+)_F_(.+)$/ ) {
124 #print "check -$file:$.:$func:$n\n";
130 if ( $lib ne $errlib ) {
131 print "$file:$.:$func:$n [${errlib}err]\n";
137 if ( $n ne $func && $errlib ne "SYS" ) {
138 print "$file:$.:$func:$n\n";
143 # print "$func:$1\n";
149 if ( $bad && $err_strict ) {
150 print STDERR "FATAL: error discrepancy\n";