~ubuntu-branches/ubuntu/utopic/openssl/utopic

« back to all changes in this revision

Viewing changes to util/mkerr.pl

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2011-04-02 13:19:19 UTC
  • mfrom: (1.2.1 upstream) (11.2.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: james.westby@ubuntu.com-20110402131919-anszuslper64ey9e
Tags: 1.0.0d-1
* New upstream version
  - Fixes CVE-2011-0014
* Make libssl-doc Replaces/Breaks with old libssl-dev packages
  (Closes: #607609)
* Only export the symbols we should, instead of all.
* Add symbol file.
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
 
1
#!/usr/local/bin/perl -w
2
2
 
3
3
my $config = "crypto/err/openssl.ec";
 
4
my $hprefix = "openssl/";
4
5
my $debug = 0;
5
6
my $rebuild = 0;
6
7
my $static = 1;
12
13
my $pack_errcode;
13
14
my $load_errcode;
14
15
 
 
16
my $errcount;
 
17
 
15
18
while (@ARGV) {
16
19
        my $arg = $ARGV[0];
17
20
        if($arg eq "-conf") {
18
21
                shift @ARGV;
19
22
                $config = shift @ARGV;
 
23
        } elsif($arg eq "-hprefix") {
 
24
                shift @ARGV;
 
25
                $hprefix = shift @ARGV;
20
26
        } elsif($arg eq "-debug") {
21
27
                $debug = 1;
22
28
                shift @ARGV;
38
44
        } elsif($arg eq "-write") {
39
45
                $dowrite = 1;
40
46
                shift @ARGV;
 
47
        } elsif($arg eq "-help" || $arg eq "-h" || $arg eq "-?" || $arg eq "--help") {
 
48
                print STDERR <<"EOF";
 
49
mkerr.pl [options] ...
 
50
 
 
51
Options:
 
52
 
 
53
  -conf F       Use the config file F instead of the default one:
 
54
                  crypto/err/openssl.ec
 
55
 
 
56
  -hprefix P    Prepend the filenames in generated #include <header>
 
57
                statements with prefix P. Default: 'openssl/' (without
 
58
                the quotes, naturally)
 
59
 
 
60
  -debug        Turn on debugging verbose output on stderr.
 
61
 
 
62
  -rebuild      Rebuild all header and C source files, irrespective of the
 
63
                fact if any error or function codes have been added/removed.
 
64
                Default: only update files for libraries which saw change
 
65
                         (of course, this requires '-write' as well, or no
 
66
                          files will be touched!)
 
67
 
 
68
  -recurse      scan a preconfigured set of directories / files for error and
 
69
                function codes:
 
70
                  (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <apps/*.c>)
 
71
                When this option is NOT specified, the filelist is taken from
 
72
                the commandline instead. Here, wildcards may be embedded. (Be
 
73
                sure to escape those to prevent the shell from expanding them
 
74
                for you when you wish mkerr.pl to do so instead.)
 
75
                Default: take file list to scan from the command line.
 
76
 
 
77
  -reindex      Discard the numeric values previously assigned to the error
 
78
                and function codes as extracted from the scanned header files;
 
79
                instead renumber all of them starting from 100. (Note that
 
80
                the numbers assigned through 'R' records in the config file
 
81
                remain intact.)
 
82
                Default: keep previously assigned numbers. (You are warned
 
83
                         when collisions are detected.)
 
84
 
 
85
  -nostatic     Generates a different source code, where these additional 
 
86
                functions are generated for each library specified in the
 
87
                config file:
 
88
                  void ERR_load_<LIB>_strings(void);
 
89
                  void ERR_unload_<LIB>_strings(void);
 
90
                  void ERR_<LIB>_error(int f, int r, char *fn, int ln);
 
91
                  #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__)
 
92
                while the code facilitates the use of these in an environment
 
93
                where the error support routines are dynamically loaded at 
 
94
                runtime.
 
95
                Default: 'static' code generation.
 
96
 
 
97
  -staticloader Prefix generated functions with the 'static' scope modifier.
 
98
                Default: don't write any scope modifier prefix.
 
99
 
 
100
  -write        Actually (over)write the generated code to the header and C 
 
101
                source files as assigned to each library through the config 
 
102
                file.
 
103
                Default: don't write.
 
104
 
 
105
  -help / -h / -? / --help            Show this help text.
 
106
 
 
107
  ...           Additional arguments are added to the file list to scan,
 
108
                assuming '-recurse' was NOT specified on the command line.
 
109
 
 
110
EOF
 
111
                exit 1;
41
112
        } else {
42
113
                last;
43
114
        }
44
115
}
45
116
 
46
117
if($recurse) {
47
 
        @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>,
48
 
                        <fips/*.c>, <fips/*/*.c>);
 
118
        @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
49
119
} else {
50
120
        @source = @ARGV;
51
121
}
64
134
                $cskip{$3} = $1;
65
135
                if($3 ne "NONE") {
66
136
                        $csrc{$1} = $3;
67
 
                        $fmax{$1} = 99;
68
 
                        $rmax{$1} = 99;
 
137
                        $fmax{$1} = 100;
 
138
                        $rmax{$1} = 100;
69
139
                        $fassigned{$1} = ":";
70
140
                        $rassigned{$1} = ":";
71
141
                        $fnew{$1} = 0;
191
261
                        if($1 eq "R") {
192
262
                                $rcodes{$name} = $code;
193
263
                                if ($rassigned{$lib} =~ /:$code:/) {
194
 
                                        print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
 
264
                                        print STDERR "!! ERROR: $lib reason code $code assigned twice (collision at $name)\n";
 
265
                                        ++$errcount;
195
266
                                }
196
267
                                $rassigned{$lib} .= "$code:";
197
268
                                if(!(exists $rextra{$name}) &&
200
271
                                }
201
272
                        } else {
202
273
                                if ($fassigned{$lib} =~ /:$code:/) {
203
 
                                        print STDERR "!! ERROR: $lib function code $code assigned twice\n";
 
274
                                        print STDERR "!! ERROR: $lib function code $code assigned twice (collision at $name)\n";
 
275
                                        ++$errcount;
204
276
                                }
205
277
                                $fassigned{$lib} .= "$code:";
206
278
                                if($code > $fmax{$lib}) {
231
303
                if ($rmax{$lib} >= 1000) {
232
304
                        print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
233
305
                        print STDERR "!!        Any new alerts must be added to $config.\n";
 
306
                        ++$errcount;
234
307
                        print STDERR "\n";
235
308
                }
236
309
        }
255
328
        print STDERR "File loaded: ".$file."\r" if $debug;
256
329
        open(IN, "<$file") || die "Can't open source file $file\n";
257
330
        while(<IN>) {
 
331
                # skip obsoleted source files entirely!
 
332
                last if(/^#error\s+obsolete/);
 
333
 
258
334
                if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
259
335
                        next unless exists $csrc{$2};
260
336
                        next if($1 eq "BIO_F_BUFFER_CTX");
264
340
                                $fnew{$2}++;
265
341
                        }
266
342
                        $notrans{$1} = 1 unless exists $ftrans{$3};
 
343
                        print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name: $3)\n" if $debug; 
267
344
                }
268
345
                if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
269
346
                        next unless exists $csrc{$2};
272
349
                                $rcodes{$1} = "X";
273
350
                                $rnew{$2}++;
274
351
                        }
 
352
                        print STDERR "Reason: $1\t= $rcodes{$1} (lib: $2)\n" if $debug; 
275
353
                } 
276
354
        }
277
355
        close IN;
313
391
        } else {
314
392
            push @out,
315
393
"/* ====================================================================\n",
316
 
" * Copyright (c) 2001-2010 The OpenSSL Project.  All rights reserved.\n",
 
394
" * Copyright (c) 2001-2011 The OpenSSL Project.  All rights reserved.\n",
317
395
" *\n",
318
396
" * Redistribution and use in source and binary forms, with or without\n",
319
397
" * modification, are permitted provided that the following conditions\n",
369
447
"#ifndef HEADER_${lib}_ERR_H\n",
370
448
"#define HEADER_${lib}_ERR_H\n",
371
449
"\n",
 
450
"#ifdef  __cplusplus\n",
 
451
"extern \"C\" {\n",
 
452
"#endif\n",
 
453
"\n",
372
454
"/* BEGIN ERROR CODES */\n";
373
455
        }
374
456
        open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
455
537
                        if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
456
538
                                $err_reason_strings{$1} = $2;
457
539
                        }
 
540
                        if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) {
 
541
                                if (!exists $ftrans{$1} && ($1 ne $2)) {
 
542
                                        print STDERR "WARNING: Mismatched function string $2\n";
 
543
                                        $ftrans{$1} = $2;
 
544
                                }
 
545
                        }
458
546
                }
459
547
                close(IN);
460
548
        }
461
549
 
 
550
 
462
551
        my $hincf;
463
552
        if($static) {
464
553
                $hfile =~ /([^\/]+)$/;
465
 
                $hincf = "<openssl/$1>";
 
554
                $hincf = "<${hprefix}$1>";
466
555
        } else {
467
556
                $hincf = "\"$hfile\"";
468
557
        }
713
802
                print STDERR "$_\n";
714
803
        }
715
804
}
 
805
 
 
806
if($errcount) {
 
807
        print STDERR "There were errors, failing...\n\n";
 
808
        exit $errcount;
 
809
}
 
810