diff options
Diffstat (limited to 'src/lib/libcrypto/util/mkerr.pl')
-rw-r--r-- | src/lib/libcrypto/util/mkerr.pl | 135 |
1 files changed, 98 insertions, 37 deletions
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl index 9678514604..53e14ab4df 100644 --- a/src/lib/libcrypto/util/mkerr.pl +++ b/src/lib/libcrypto/util/mkerr.pl | |||
@@ -44,8 +44,7 @@ while (@ARGV) { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | if($recurse) { | 46 | if($recurse) { |
47 | @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <fips-1.0/*.c>, | 47 | @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>); |
48 | <fips-1.0/*/*.c>); | ||
49 | } else { | 48 | } else { |
50 | @source = @ARGV; | 49 | @source = @ARGV; |
51 | } | 50 | } |
@@ -66,6 +65,8 @@ while(<IN>) | |||
66 | $csrc{$1} = $3; | 65 | $csrc{$1} = $3; |
67 | $fmax{$1} = 99; | 66 | $fmax{$1} = 99; |
68 | $rmax{$1} = 99; | 67 | $rmax{$1} = 99; |
68 | $fassigned{$1} = ":"; | ||
69 | $rassigned{$1} = ":"; | ||
69 | $fnew{$1} = 0; | 70 | $fnew{$1} = 0; |
70 | $rnew{$1} = 0; | 71 | $rnew{$1} = 0; |
71 | } | 72 | } |
@@ -104,15 +105,24 @@ while (($hdr, $lib) = each %libinc) | |||
104 | next; | 105 | next; |
105 | } | 106 | } |
106 | 107 | ||
107 | $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration | 108 | if(/\/\*/) { |
109 | if (not /\*\//) { # multiline comment... | ||
110 | $line = $_; # ... just accumulate | ||
111 | next; | ||
112 | } else { | ||
113 | s/\/\*.*?\*\///gs; # wipe it | ||
114 | } | ||
115 | } | ||
116 | |||
108 | if ($cpp) { | 117 | if ($cpp) { |
109 | $cpp = 0 if /^#.*endif/; | 118 | $cpp++ if /^#\s*if/; |
119 | $cpp-- if /^#\s*endif/; | ||
110 | next; | 120 | next; |
111 | } | 121 | } |
122 | $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration | ||
112 | 123 | ||
113 | next if (/^\#/); # skip preprocessor directives | 124 | next if (/^\#/); # skip preprocessor directives |
114 | 125 | ||
115 | s/\/\*.*?\*\///gs; # ignore comments | ||
116 | s/{[^{}]*}//gs; # ignore {} blocks | 126 | s/{[^{}]*}//gs; # ignore {} blocks |
117 | 127 | ||
118 | if (/\{|\/\*/) { # Add a } so editor works... | 128 | if (/\{|\/\*/) { # Add a } so editor works... |
@@ -125,31 +135,37 @@ while (($hdr, $lib) = each %libinc) | |||
125 | 135 | ||
126 | print STDERR " \r" if $debug; | 136 | print STDERR " \r" if $debug; |
127 | $defnr = 0; | 137 | $defnr = 0; |
138 | # Delete any DECLARE_ macros | ||
139 | $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs; | ||
128 | foreach (split /;/, $def) { | 140 | foreach (split /;/, $def) { |
129 | $defnr++; | 141 | $defnr++; |
130 | print STDERR "def: $defnr\r" if $debug; | 142 | print STDERR "def: $defnr\r" if $debug; |
131 | 143 | ||
144 | # The goal is to collect function names from function declarations. | ||
145 | |||
132 | s/^[\n\s]*//g; | 146 | s/^[\n\s]*//g; |
133 | s/[\n\s]*$//g; | 147 | s/[\n\s]*$//g; |
134 | next if(/typedef\W/); | 148 | |
135 | if (/\(\*(\w*)\([^\)]+/) { | 149 | # Skip over recognized non-function declarations |
136 | my $name = $1; | 150 | next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/); |
137 | $name =~ tr/[a-z]/[A-Z]/; | 151 | |
138 | $ftrans{$name} = $1; | 152 | # Remove STACK_OF(foo) |
139 | } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){ | 153 | s/STACK_OF\(\w+\)/void/; |
140 | # K&R C | 154 | |
141 | next ; | 155 | # Reduce argument lists to empty () |
142 | } elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) { | 156 | # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} |
143 | while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) { | 157 | while(/\(.*\)/s) { |
144 | s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s; | 158 | s/\([^\(\)]+\)/\{\}/gs; |
145 | s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s; | 159 | s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f |
146 | } | 160 | } |
147 | s/\(void\)//; | 161 | # pretend as we didn't use curly braces: {} -> () |
148 | /(\w+(\{[0-9]+\})?)\W*\(\)/s; | 162 | s/\{\}/\(\)/gs; |
149 | my $name = $1; | 163 | |
164 | if (/(\w+)\s*\(\).*/s) { # first token prior [first] () is | ||
165 | my $name = $1; # a function name! | ||
150 | $name =~ tr/[a-z]/[A-Z]/; | 166 | $name =~ tr/[a-z]/[A-Z]/; |
151 | $ftrans{$name} = $1; | 167 | $ftrans{$name} = $1; |
152 | } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) { | 168 | } elsif (/[\(\)]/ and not (/=/)) { |
153 | print STDERR "Header $hdr: cannot parse: $_;\n"; | 169 | print STDERR "Header $hdr: cannot parse: $_;\n"; |
154 | } | 170 | } |
155 | } | 171 | } |
@@ -162,7 +178,7 @@ while (($hdr, $lib) = each %libinc) | |||
162 | # maximum code used. | 178 | # maximum code used. |
163 | 179 | ||
164 | if ($gotfile) { | 180 | if ($gotfile) { |
165 | while(<IN>) { | 181 | while(<IN>) { |
166 | if(/^\#define\s+(\S+)\s+(\S+)/) { | 182 | if(/^\#define\s+(\S+)\s+(\S+)/) { |
167 | $name = $1; | 183 | $name = $1; |
168 | $code = $2; | 184 | $code = $2; |
@@ -173,18 +189,49 @@ while (($hdr, $lib) = each %libinc) | |||
173 | } | 189 | } |
174 | if($1 eq "R") { | 190 | if($1 eq "R") { |
175 | $rcodes{$name} = $code; | 191 | $rcodes{$name} = $code; |
192 | if ($rassigned{$lib} =~ /:$code:/) { | ||
193 | print STDERR "!! ERROR: $lib reason code $code assigned twice\n"; | ||
194 | } | ||
195 | $rassigned{$lib} .= "$code:"; | ||
176 | if(!(exists $rextra{$name}) && | 196 | if(!(exists $rextra{$name}) && |
177 | ($code > $rmax{$lib}) ) { | 197 | ($code > $rmax{$lib}) ) { |
178 | $rmax{$lib} = $code; | 198 | $rmax{$lib} = $code; |
179 | } | 199 | } |
180 | } else { | 200 | } else { |
201 | if ($fassigned{$lib} =~ /:$code:/) { | ||
202 | print STDERR "!! ERROR: $lib function code $code assigned twice\n"; | ||
203 | } | ||
204 | $fassigned{$lib} .= "$code:"; | ||
181 | if($code > $fmax{$lib}) { | 205 | if($code > $fmax{$lib}) { |
182 | $fmax{$lib} = $code; | 206 | $fmax{$lib} = $code; |
183 | } | 207 | } |
184 | $fcodes{$name} = $code; | 208 | $fcodes{$name} = $code; |
185 | } | 209 | } |
186 | } | 210 | } |
187 | } | 211 | } |
212 | } | ||
213 | |||
214 | if ($debug) { | ||
215 | if (defined($fmax{$lib})) { | ||
216 | print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n"; | ||
217 | $fassigned{$lib} =~ m/^:(.*):$/; | ||
218 | @fassigned = sort {$a <=> $b} split(":", $1); | ||
219 | print STDERR " @fassigned\n"; | ||
220 | } | ||
221 | if (defined($rmax{$lib})) { | ||
222 | print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n"; | ||
223 | $rassigned{$lib} =~ m/^:(.*):$/; | ||
224 | @rassigned = sort {$a <=> $b} split(":", $1); | ||
225 | print STDERR " @rassigned\n"; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | if ($lib eq "SSL") { | ||
230 | if ($rmax{$lib} >= 1000) { | ||
231 | print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n"; | ||
232 | print STDERR "!! Any new alerts must be added to $config.\n"; | ||
233 | print STDERR "\n"; | ||
234 | } | ||
188 | } | 235 | } |
189 | close IN; | 236 | close IN; |
190 | } | 237 | } |
@@ -201,11 +248,10 @@ while (($hdr, $lib) = each %libinc) | |||
201 | # so all those unreferenced can be printed out. | 248 | # so all those unreferenced can be printed out. |
202 | 249 | ||
203 | 250 | ||
204 | print STDERR "Files loaded: " if $debug; | ||
205 | foreach $file (@source) { | 251 | foreach $file (@source) { |
206 | # Don't parse the error source file. | 252 | # Don't parse the error source file. |
207 | next if exists $cskip{$file}; | 253 | next if exists $cskip{$file}; |
208 | print STDERR $file if $debug; | 254 | print STDERR "File loaded: ".$file."\r" if $debug; |
209 | open(IN, "<$file") || die "Can't open source file $file\n"; | 255 | open(IN, "<$file") || die "Can't open source file $file\n"; |
210 | while(<IN>) { | 256 | while(<IN>) { |
211 | if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { | 257 | if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { |
@@ -229,7 +275,7 @@ foreach $file (@source) { | |||
229 | } | 275 | } |
230 | close IN; | 276 | close IN; |
231 | } | 277 | } |
232 | print STDERR "\n" if $debug; | 278 | print STDERR " \n" if $debug; |
233 | 279 | ||
234 | # Now process each library in turn. | 280 | # Now process each library in turn. |
235 | 281 | ||
@@ -266,7 +312,7 @@ foreach $lib (keys %csrc) | |||
266 | } else { | 312 | } else { |
267 | push @out, | 313 | push @out, |
268 | "/* ====================================================================\n", | 314 | "/* ====================================================================\n", |
269 | " * Copyright (c) 2001-2005 The OpenSSL Project. All rights reserved.\n", | 315 | " * Copyright (c) 2001-2008 The OpenSSL Project. All rights reserved.\n", |
270 | " *\n", | 316 | " *\n", |
271 | " * Redistribution and use in source and binary forms, with or without\n", | 317 | " * Redistribution and use in source and binary forms, with or without\n", |
272 | " * modification, are permitted provided that the following conditions\n", | 318 | " * modification, are permitted provided that the following conditions\n", |
@@ -356,7 +402,16 @@ EOF | |||
356 | foreach $i (@function) { | 402 | foreach $i (@function) { |
357 | $z=6-int(length($i)/8); | 403 | $z=6-int(length($i)/8); |
358 | if($fcodes{$i} eq "X") { | 404 | if($fcodes{$i} eq "X") { |
359 | $fcodes{$i} = ++$fmax{$lib}; | 405 | $fassigned{$lib} =~ m/^:([^:]*):/; |
406 | $findcode = $1; | ||
407 | if (!defined($findcode)) { | ||
408 | $findcode = $fmax{$lib}; | ||
409 | } | ||
410 | while ($fassigned{$lib} =~ m/:$findcode:/) { | ||
411 | $findcode++; | ||
412 | } | ||
413 | $fcodes{$i} = $findcode; | ||
414 | $fassigned{$lib} .= "$findcode:"; | ||
360 | print STDERR "New Function code $i\n" if $debug; | 415 | print STDERR "New Function code $i\n" if $debug; |
361 | } | 416 | } |
362 | printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z; | 417 | printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z; |
@@ -367,7 +422,16 @@ EOF | |||
367 | foreach $i (@reasons) { | 422 | foreach $i (@reasons) { |
368 | $z=6-int(length($i)/8); | 423 | $z=6-int(length($i)/8); |
369 | if($rcodes{$i} eq "X") { | 424 | if($rcodes{$i} eq "X") { |
370 | $rcodes{$i} = ++$rmax{$lib}; | 425 | $rassigned{$lib} =~ m/^:([^:]*):/; |
426 | $findcode = $1; | ||
427 | if (!defined($findcode)) { | ||
428 | $findcode = $rmax{$lib}; | ||
429 | } | ||
430 | while ($rassigned{$lib} =~ m/:$findcode:/) { | ||
431 | $findcode++; | ||
432 | } | ||
433 | $rcodes{$i} = $findcode; | ||
434 | $rassigned{$lib} .= "$findcode:"; | ||
371 | print STDERR "New Reason code $i\n" if $debug; | 435 | print STDERR "New Reason code $i\n" if $debug; |
372 | } | 436 | } |
373 | printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z; | 437 | printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z; |
@@ -422,7 +486,7 @@ EOF | |||
422 | print OUT <<"EOF"; | 486 | print OUT <<"EOF"; |
423 | /* $cfile */ | 487 | /* $cfile */ |
424 | /* ==================================================================== | 488 | /* ==================================================================== |
425 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 489 | * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. |
426 | * | 490 | * |
427 | * Redistribution and use in source and binary forms, with or without | 491 | * Redistribution and use in source and binary forms, with or without |
428 | * modification, are permitted provided that the following conditions | 492 | * modification, are permitted provided that the following conditions |
@@ -536,17 +600,14 @@ if($static) { | |||
536 | 600 | ||
537 | ${staticloader}void ERR_load_${lib}_strings(void) | 601 | ${staticloader}void ERR_load_${lib}_strings(void) |
538 | { | 602 | { |
539 | static int init=1; | 603 | #ifndef OPENSSL_NO_ERR |
540 | 604 | ||
541 | if (init) | 605 | if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL) |
542 | { | 606 | { |
543 | init=0; | ||
544 | #ifndef OPENSSL_NO_ERR | ||
545 | ERR_load_strings($load_errcode,${lib}_str_functs); | 607 | ERR_load_strings($load_errcode,${lib}_str_functs); |
546 | ERR_load_strings($load_errcode,${lib}_str_reasons); | 608 | ERR_load_strings($load_errcode,${lib}_str_reasons); |
547 | #endif | ||
548 | |||
549 | } | 609 | } |
610 | #endif | ||
550 | } | 611 | } |
551 | EOF | 612 | EOF |
552 | } else { | 613 | } else { |