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