1 1.1.1.2 christos #! /usr/bin/env perl 2 1.1.1.2 christos # Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos # 4 1.1.1.2 christos # Licensed under the OpenSSL license (the "License"). You may not use 5 1.1.1.2 christos # this file except in compliance with the License. You can obtain a copy 6 1.1.1.2 christos # in the file LICENSE in the source distribution or at 7 1.1.1.2 christos # https://www.openssl.org/source/license.html 8 1.1.1.2 christos 9 1.1 christos # This is just a quick script to scan for cases where the 'error' 10 1.1 christos # function name in a XXXerr() macro is wrong. 11 1.1.1.2 christos # 12 1.1 christos # Run in the top level by going 13 1.1 christos # perl util/ck_errf.pl */*.c */*/*.c 14 1.1 christos # 15 1.1 christos 16 1.1.1.2 christos use strict; 17 1.1.1.2 christos use warnings; 18 1.1.1.2 christos 19 1.1.1.2 christos my $config; 20 1.1 christos my $err_strict = 0; 21 1.1.1.2 christos my $debug = 0; 22 1.1.1.2 christos my $internal = 0; 23 1.1 christos 24 1.1.1.2 christos sub help 25 1.1.1.2 christos { 26 1.1.1.2 christos print STDERR <<"EOF"; 27 1.1.1.2 christos mkerr.pl [options] [files...] 28 1.1.1.2 christos 29 1.1.1.2 christos Options: 30 1.1.1.2 christos 31 1.1.1.2 christos -conf FILE Use the named config file FILE instead of the default. 32 1.1.1.2 christos 33 1.1.1.2 christos -debug Verbose output debugging on stderr. 34 1.1.1.2 christos 35 1.1.1.2 christos -internal Generate code that is to be built as part of OpenSSL itself. 36 1.1.1.2 christos Also scans internal list of files. 37 1.1.1.2 christos 38 1.1.1.2 christos -strict If any error was found, fail with exit code 1, otherwise 0. 39 1.1.1.2 christos 40 1.1.1.2 christos -help Show this help text. 41 1.1.1.2 christos 42 1.1.1.2 christos ... Additional arguments are added to the file list to scan, 43 1.1.1.2 christos if '-internal' was NOT specified on the command line. 44 1.1.1.2 christos 45 1.1.1.2 christos EOF 46 1.1.1.2 christos } 47 1.1.1.2 christos 48 1.1.1.2 christos while ( @ARGV ) { 49 1.1.1.2 christos my $arg = $ARGV[0]; 50 1.1.1.2 christos last unless $arg =~ /-.*/; 51 1.1.1.2 christos $arg = $1 if $arg =~ /-(-.*)/; 52 1.1.1.2 christos if ( $arg eq "-conf" ) { 53 1.1.1.2 christos $config = $ARGV[1]; 54 1.1.1.2 christos shift @ARGV; 55 1.1.1.2 christos } elsif ( $arg eq "-debug" ) { 56 1.1.1.2 christos $debug = 1; 57 1.1.1.2 christos } elsif ( $arg eq "-internal" ) { 58 1.1.1.2 christos $internal = 1; 59 1.1.1.2 christos } elsif ( $arg eq "-strict" ) { 60 1.1.1.2 christos $err_strict = 1; 61 1.1.1.2 christos } elsif ( $arg =~ /-*h(elp)?/ ) { 62 1.1.1.2 christos &help(); 63 1.1.1.2 christos exit; 64 1.1.1.2 christos } elsif ( $arg =~ /-.*/ ) { 65 1.1.1.2 christos die "Unknown option $arg; use -h for help.\n"; 66 1.1.1.2 christos } 67 1.1.1.2 christos shift @ARGV; 68 1.1.1.2 christos } 69 1.1.1.2 christos 70 1.1.1.2 christos my @source; 71 1.1.1.2 christos if ( $internal ) { 72 1.1.1.2 christos die "Extra parameters given.\n" if @ARGV; 73 1.1.1.2 christos $config = "crypto/err/openssl.ec" unless defined $config; 74 1.1.1.2 christos @source = ( glob('crypto/*.c'), glob('crypto/*/*.c'), 75 1.1.1.2 christos glob('ssl/*.c'), glob('ssl/*/*.c') ); 76 1.1.1.2 christos } else { 77 1.1.1.2 christos die "Configuration file not given.\nSee '$0 -help' for information\n" 78 1.1.1.2 christos unless defined $config; 79 1.1.1.2 christos @source = @ARGV; 80 1.1.1.2 christos } 81 1.1.1.2 christos 82 1.1.1.2 christos # To detect if there is any error generation for a libcrypto/libssl libs 83 1.1.1.2 christos # we don't know, we need to find out what libs we do know. That list is 84 1.1.1.2 christos # readily available in crypto/err/openssl.ec, in form of lines starting 85 1.1.1.2 christos # with "L ". Note that we always rely on the modules SYS and ERR to be 86 1.1.1.2 christos # generally available. 87 1.1.1.2 christos my %libs = ( SYS => 1, ERR => 1 ); 88 1.1.1.2 christos open my $cfh, $config or die "Trying to read $config: $!\n"; 89 1.1.1.2 christos while (<$cfh>) { 90 1.1.1.2 christos s|\R$||; # Better chomp 91 1.1.1.2 christos next unless m|^L ([0-9A-Z_]+)\s|; 92 1.1.1.2 christos next if $1 eq "NONE"; 93 1.1.1.2 christos $libs{$1} = 1; 94 1.1.1.2 christos } 95 1.1 christos 96 1.1.1.2 christos my $bad = 0; 97 1.1.1.2 christos foreach my $file (@source) { 98 1.1.1.2 christos open( IN, "<$file" ) || die "Can't open $file, $!"; 99 1.1.1.2 christos my $func = ""; 100 1.1.1.2 christos while (<IN>) { 101 1.1.1.2 christos if ( !/;$/ && /^\**([a-zA-Z_].*[\s*])?([A-Za-z_0-9]+)\(.*([),]|$)/ ) { 102 1.1.1.2 christos /^([^()]*(\([^()]*\)[^()]*)*)\(/; 103 1.1.1.2 christos $1 =~ /([A-Za-z_0-9]*)$/; 104 1.1.1.2 christos $func = $1; 105 1.1.1.2 christos $func =~ tr/A-Z/a-z/; 106 1.1.1.2 christos } 107 1.1.1.2 christos if ( /([A-Z0-9_]+[A-Z0-9])err\(([^,]+)/ && !/ckerr_ignore/ ) { 108 1.1.1.2 christos my $errlib = $1; 109 1.1.1.2 christos my $n = $2; 110 1.1.1.2 christos 111 1.1.1.2 christos unless ( $libs{$errlib} ) { 112 1.1.1.2 christos print "$file:$.:$errlib not listed in $config\n"; 113 1.1.1.2 christos $libs{$errlib} = 1; # To not display it again 114 1.1.1.2 christos $bad = 1; 115 1.1.1.2 christos } 116 1.1.1.2 christos 117 1.1.1.2 christos if ( $func eq "" ) { 118 1.1.1.2 christos print "$file:$.:???:$n\n"; 119 1.1.1.2 christos $bad = 1; 120 1.1.1.2 christos next; 121 1.1.1.2 christos } 122 1.1.1.2 christos 123 1.1.1.2 christos if ( $n !~ /^(.+)_F_(.+)$/ ) { 124 1.1.1.2 christos #print "check -$file:$.:$func:$n\n"; 125 1.1.1.2 christos next; 126 1.1.1.2 christos } 127 1.1.1.2 christos my $lib = $1; 128 1.1.1.2 christos $n = $2; 129 1.1.1.2 christos 130 1.1.1.2 christos if ( $lib ne $errlib ) { 131 1.1.1.2 christos print "$file:$.:$func:$n [${errlib}err]\n"; 132 1.1.1.2 christos $bad = 1; 133 1.1.1.2 christos next; 134 1.1.1.2 christos } 135 1.1.1.2 christos 136 1.1.1.2 christos $n =~ tr/A-Z/a-z/; 137 1.1.1.2 christos if ( $n ne $func && $errlib ne "SYS" ) { 138 1.1.1.2 christos print "$file:$.:$func:$n\n"; 139 1.1.1.2 christos $bad = 1; 140 1.1.1.2 christos next; 141 1.1.1.2 christos } 142 1.1 christos 143 1.1.1.2 christos # print "$func:$1\n"; 144 1.1.1.2 christos } 145 1.1.1.2 christos } 146 1.1.1.2 christos close(IN); 147 1.1.1.2 christos } 148 1.1.1.2 christos 149 1.1.1.2 christos if ( $bad && $err_strict ) { 150 1.1.1.2 christos print STDERR "FATAL: error discrepancy\n"; 151 1.1.1.2 christos exit 1; 152 1.1.1.2 christos } 153