3 # Find functions making recursive calls to themselves.
4 # (Multiple recursion where a() calls b() which calls a() not covered.)
6 # When the recursion depth might depend on data controlled by the attacker in
7 # an unbounded way, those functions should use interation instead.
9 # Typical usage: scripts/recursion.pl library/*.c
15 use open qw(:std utf8);
17 # exclude functions that are ok:
18 # - mpi_write_hlp: bounded by size of mbedtls_mpi, a compile-time constant
19 # - x509_crt_verify_child: bounded by MBEDTLS_X509_MAX_INTERMEDIATE_CA
20 my $known_ok = qr/mpi_write_hlp|x509_crt_verify_child/;
26 die "Usage: $0 file.c [...]\n" unless @ARGV;
30 if( /^[^\/#{}\s]/ && ! /\[.*]/ ) {
31 chomp( $cur_name = $_ ) unless $inside;
32 } elsif( /^{/ && $cur_name ) {
34 $cur_name =~ s/.* ([^ ]*)\(.*/$1/;
35 } elsif( /^}/ && $inside ) {
38 } elsif( $inside && /\b\Q$cur_name\E\([^)]/ ) {
39 push @funcs, $cur_name unless /$known_ok/;
43 print "$_\n" for @funcs;