]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/progs.pl
Bounds check string functions in apps.
[thirdparty/openssl.git] / apps / progs.pl
CommitLineData
e0a65194 1#! /usr/bin/env perl
4d0eac19 2# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3850f8cb 3#
e0a65194
RS
4# Licensed under the OpenSSL license (the "License"). You may not use
5# this file except in compliance with the License. You can obtain a copy
6# in the file LICENSE in the source distribution or at
3850f8cb 7# https://www.openssl.org/source/license.html
3850f8cb 8
fb3e2a88
RL
9# Generate progs.h file by looking for command mains in list of C files
10# passed on the command line.
11
12use strict;
13use warnings;
6a74806e
RL
14use lib '.';
15use configdata qw/@disablables %unified_info/;
fb3e2a88 16
aa74c2ec
RS
17my %commands = ();
18my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
6a74806e 19my $apps_openssl = shift @ARGV;
aa74c2ec 20
6a74806e
RL
21# because the program apps/openssl has object files as sources, and
22# they then have the corresponding C files as source, we need to chain
23# the lookups in %unified_info
24my @openssl_source =
25 map { @{$unified_info{sources}->{$_}} }
aa74c2ec 26 @{$unified_info{sources}->{$apps_openssl}};
6a74806e
RL
27
28foreach my $filename (@openssl_source) {
aa74c2ec
RS
29 open F, $filename or die "Coudn't open $_: $!\n";
30 foreach ( grep /$cmdre/, <F> ) {
31 my @foo = /$cmdre/;
32 $commands{$1} = 1;
33 }
34 close F;
fb3e2a88
RL
35}
36
37@ARGV = sort keys %commands;
d02b48c6
RE
38
39print <<'EOF';
7e1b7485 40/*
e0a65194
RS
41 * WARNING: do not edit!
42 * Generated by apps/progs.pl
43 *
4d0eac19 44 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3850f8cb 45 *
e0a65194
RS
46 * Licensed under the OpenSSL license (the "License"). You may not use
47 * this file except in compliance with the License. You can obtain a copy
48 * in the file LICENSE in the source distribution or at
3850f8cb 49 * https://www.openssl.org/source/license.html
7e1b7485 50 */
d02b48c6 51
7e1b7485
RS
52typedef enum FUNC_TYPE {
53 FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
54 FT_md_alg, FT_cipher_alg
55} FUNC_TYPE;
d02b48c6 56
7e1b7485
RS
57typedef struct function_st {
58 FUNC_TYPE type;
474e469b 59 const char *name;
dc57696c 60 int (*func)(int argc, char *argv[]);
7e1b7485 61 const OPTIONS *help;
474e469b 62} FUNCTION;
d02b48c6 63
89d6aa10 64DEFINE_LHASH_OF(FUNCTION);
e6b5c341 65
d02b48c6
RE
66EOF
67
7e1b7485 68foreach (@ARGV) {
aa74c2ec 69 printf "extern int %s_main(int argc, char *argv[]);\n", $_;
7e1b7485 70}
df2ee0e2
BL
71print "\n";
72
7e1b7485 73foreach (@ARGV) {
aa74c2ec 74 printf "extern const OPTIONS %s_options[];\n", $_;
7e1b7485 75}
aa74c2ec 76print "\n";
3850f8cb
RL
77
78my %cmd_disabler = (
79 ciphers => "sock",
80 genrsa => "rsa",
81 rsautl => "rsa",
82 gendsa => "dsa",
83 dsaparam => "dsa",
84 gendh => "dh",
85 dhparam => "dh",
86 ecparam => "ec",
87 pkcs12 => "des",
aa74c2ec
RS
88);
89
90print "#ifdef INCLUDE_FUNCTION_TABLE\n";
91print "static FUNCTION functions[] = {\n";
92foreach my $cmd ( @ARGV ) {
93 my $str = " {FT_general, \"$cmd\", ${cmd}_main, ${cmd}_options},\n";
94 if ($cmd =~ /^s_/) {
95 print "#ifndef OPENSSL_NO_SOCK\n${str}#endif\n";
96 } elsif (grep { $cmd eq $_ } @disablables) {
97 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
98 } elsif (my $disabler = $cmd_disabler{$cmd}) {
99 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
100 } else {
101 print $str;
102 }
7e1b7485 103}
d02b48c6 104
3850f8cb 105my %md_disabler = (
3850f8cb
RL
106 blake2b512 => "blake2",
107 blake2s256 => "blake2",
aa74c2ec 108);
3850f8cb 109foreach my $cmd (
7e1b7485 110 "md2", "md4", "md5",
168c3b73 111 "gost",
a173a7ee 112 "sha1", "sha224", "sha256", "sha384", "sha512",
03f03129 113 "mdc2", "rmd160", "blake2b512", "blake2s256"
7e1b7485 114) {
aa74c2ec
RS
115 my $str = " {FT_md, \"$cmd\", dgst_main},\n";
116 if (grep { $cmd eq $_ } @disablables) {
117 print "#ifndef OPENSSL_NO_" . uc($cmd) . "\n${str}#endif\n";
118 } elsif (my $disabler = $md_disabler{$cmd}) {
119 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
120 } else {
121 print $str;
122 }
7e1b7485 123}
d02b48c6 124
3850f8cb
RL
125my %cipher_disabler = (
126 des3 => "des",
127 desx => "des",
128 cast5 => "cast",
aa74c2ec 129);
3850f8cb 130foreach my $cmd (
aa74c2ec
RS
131 "aes-128-cbc", "aes-128-ecb",
132 "aes-192-cbc", "aes-192-ecb",
133 "aes-256-cbc", "aes-256-ecb",
134 "aria-128-cbc", "aria-128-cfb",
135 "aria-128-ctr", "aria-128-ecb", "aria-128-ofb",
136 "aria-128-cfb1", "aria-128-cfb8",
137 "aria-192-cbc", "aria-192-cfb",
138 "aria-192-ctr", "aria-192-ecb", "aria-192-ofb",
139 "aria-192-cfb1", "aria-192-cfb8",
140 "aria-256-cbc", "aria-256-cfb",
141 "aria-256-ctr", "aria-256-ecb", "aria-256-ofb",
142 "aria-256-cfb1", "aria-256-cfb8",
143 "camellia-128-cbc", "camellia-128-ecb",
144 "camellia-192-cbc", "camellia-192-ecb",
145 "camellia-256-cbc", "camellia-256-ecb",
146 "base64", "zlib",
147 "des", "des3", "desx", "idea", "seed", "rc4", "rc4-40",
148 "rc2", "bf", "cast", "rc5",
149 "des-ecb", "des-ede", "des-ede3",
150 "des-cbc", "des-ede-cbc","des-ede3-cbc",
151 "des-cfb", "des-ede-cfb","des-ede3-cfb",
152 "des-ofb", "des-ede-ofb","des-ede3-ofb",
153 "idea-cbc","idea-ecb", "idea-cfb", "idea-ofb",
154 "seed-cbc","seed-ecb", "seed-cfb", "seed-ofb",
155 "rc2-cbc", "rc2-ecb", "rc2-cfb","rc2-ofb", "rc2-64-cbc", "rc2-40-cbc",
156 "bf-cbc", "bf-ecb", "bf-cfb", "bf-ofb",
157 "cast5-cbc","cast5-ecb", "cast5-cfb","cast5-ofb",
158 "cast-cbc", "rc5-cbc", "rc5-ecb", "rc5-cfb", "rc5-ofb"
7e1b7485 159) {
aa74c2ec
RS
160 my $str = " {FT_cipher, \"$cmd\", enc_main, enc_options},\n";
161 (my $algo = $cmd) =~ s/-.*//g;
162 if ($cmd eq "zlib") {
163 print "#ifdef ZLIB\n${str}#endif\n";
164 } elsif (grep { $algo eq $_ } @disablables) {
165 print "#ifndef OPENSSL_NO_" . uc($algo) . "\n${str}#endif\n";
166 } elsif (my $disabler = $cipher_disabler{$algo}) {
167 print "#ifndef OPENSSL_NO_" . uc($disabler) . "\n${str}#endif\n";
168 } else {
169 print $str;
170 }
7e1b7485 171}
d02b48c6 172
aa74c2ec 173print " {0, NULL, NULL}\n};\n";
ad2c5ed7 174print "#endif\n";