mbed TLS Build

Dependents:   Encrypt_Decrypt1 mbed_blink_tls encrypt encrypt

Committer:
markrad
Date:
Thu Jan 05 00:18:44 2017 +0000
Revision:
0:cdf462088d13
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
markrad 0:cdf462088d13 1 #!/usr/bin/perl
markrad 0:cdf462088d13 2
markrad 0:cdf462088d13 3 # Find functions making recursive calls to themselves.
markrad 0:cdf462088d13 4 # (Multiple recursion where a() calls b() which calls a() not covered.)
markrad 0:cdf462088d13 5 #
markrad 0:cdf462088d13 6 # When the recursion depth might depend on data controlled by the attacker in
markrad 0:cdf462088d13 7 # an unbounded way, those functions should use interation instead.
markrad 0:cdf462088d13 8 #
markrad 0:cdf462088d13 9 # Typical usage: scripts/recursion.pl library/*.c
markrad 0:cdf462088d13 10
markrad 0:cdf462088d13 11 use warnings;
markrad 0:cdf462088d13 12 use strict;
markrad 0:cdf462088d13 13
markrad 0:cdf462088d13 14 use utf8;
markrad 0:cdf462088d13 15 use open qw(:std utf8);
markrad 0:cdf462088d13 16
markrad 0:cdf462088d13 17 # exclude functions that are ok:
markrad 0:cdf462088d13 18 # - mpi_write_hlp: bounded by size of mbedtls_mpi, a compile-time constant
markrad 0:cdf462088d13 19 # - x509_crt_verify_child: bounded by MBEDTLS_X509_MAX_INTERMEDIATE_CA
markrad 0:cdf462088d13 20 my $known_ok = qr/mpi_write_hlp|x509_crt_verify_child/;
markrad 0:cdf462088d13 21
markrad 0:cdf462088d13 22 my $cur_name;
markrad 0:cdf462088d13 23 my $inside;
markrad 0:cdf462088d13 24 my @funcs;
markrad 0:cdf462088d13 25
markrad 0:cdf462088d13 26 die "Usage: $0 file.c [...]\n" unless @ARGV;
markrad 0:cdf462088d13 27
markrad 0:cdf462088d13 28 while (<>)
markrad 0:cdf462088d13 29 {
markrad 0:cdf462088d13 30 if( /^[^\/#{}\s]/ && ! /\[.*]/ ) {
markrad 0:cdf462088d13 31 chomp( $cur_name = $_ ) unless $inside;
markrad 0:cdf462088d13 32 } elsif( /^{/ && $cur_name ) {
markrad 0:cdf462088d13 33 $inside = 1;
markrad 0:cdf462088d13 34 $cur_name =~ s/.* ([^ ]*)\(.*/$1/;
markrad 0:cdf462088d13 35 } elsif( /^}/ && $inside ) {
markrad 0:cdf462088d13 36 undef $inside;
markrad 0:cdf462088d13 37 undef $cur_name;
markrad 0:cdf462088d13 38 } elsif( $inside && /\b\Q$cur_name\E\([^)]/ ) {
markrad 0:cdf462088d13 39 push @funcs, $cur_name unless /$known_ok/;
markrad 0:cdf462088d13 40 }
markrad 0:cdf462088d13 41 }
markrad 0:cdf462088d13 42
markrad 0:cdf462088d13 43 print "$_\n" for @funcs;
markrad 0:cdf462088d13 44 exit @funcs;