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