Merge pull request #3368 from gilles-peskine-arm/error-include-asn1-2.16

Backport 2.16: Include asn1.h in error.c
This commit is contained in:
Gilles Peskine 2020-05-28 15:09:27 +02:00 committed by GitHub
commit 5893bdc513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Bugfix
* Include asn1.h in error.c. Fixes #3328 reported by David Hu.

View File

@ -53,6 +53,10 @@
#include "mbedtls/aria.h" #include "mbedtls/aria.h"
#endif #endif
#if defined(MBEDTLS_ASN1_PARSE_C)
#include "mbedtls/asn1.h"
#endif
#if defined(MBEDTLS_BASE64_C) #if defined(MBEDTLS_BASE64_C)
#include "mbedtls/base64.h" #include "mbedtls/base64.h"
#endif #endif

View File

@ -48,12 +48,16 @@ close(FORMAT_FILE);
$/ = $line_separator; $/ = $line_separator;
my @files = <$include_dir/*.h>; my @files = <$include_dir/*.h>;
my @necessary_include_files;
my @matches; my @matches;
foreach my $file (@files) { foreach my $file (@files) {
open(FILE, "$file"); open(FILE, "$file");
my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, <FILE>); my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, <FILE>);
push(@matches, @grep_res); push(@matches, @grep_res);
close FILE; close FILE;
my $include_name = $file;
$include_name =~ s!.*/!!;
push @necessary_include_files, $include_name if @grep_res;
} }
my $ll_old_define = ""; my $ll_old_define = "";
@ -63,10 +67,10 @@ my $ll_code_check = "";
my $hl_code_check = ""; my $hl_code_check = "";
my $headers = ""; my $headers = "";
my %included_headers;
my %error_codes_seen; my %error_codes_seen;
foreach my $line (@matches) foreach my $line (@matches)
{ {
next if ($line =~ /compat-1.2.h/); next if ($line =~ /compat-1.2.h/);
@ -97,11 +101,12 @@ foreach my $line (@matches)
my $include_name = $module_name; my $include_name = $module_name;
$include_name =~ tr/A-Z/a-z/; $include_name =~ tr/A-Z/a-z/;
$include_name = "" if ($include_name eq "asn1");
# Fix faulty ones # Fix faulty ones
$include_name = "net_sockets" if ($module_name eq "NET"); $include_name = "net_sockets" if ($module_name eq "NET");
$included_headers{"${include_name}.h"} = $module_name;
my $found_ll = grep $_ eq $module_name, @low_level_modules; my $found_ll = grep $_ eq $module_name, @low_level_modules;
my $found_hl = grep $_ eq $module_name, @high_level_modules; my $found_hl = grep $_ eq $module_name, @high_level_modules;
if (!$found_ll && !$found_hl) if (!$found_ll && !$found_hl)
@ -205,3 +210,15 @@ $error_format =~ s/HIGH_LEVEL_CODE_CHECKS\n/$hl_code_check/g;
open(ERROR_FILE, ">$error_file") or die "Opening destination file '$error_file': $!"; open(ERROR_FILE, ">$error_file") or die "Opening destination file '$error_file': $!";
print ERROR_FILE $error_format; print ERROR_FILE $error_format;
close(ERROR_FILE); close(ERROR_FILE);
my $errors = 0;
for my $include_name (@necessary_include_files)
{
if (not $included_headers{$include_name})
{
print STDERR "The header file \"$include_name\" defines error codes but has not been included!\n";
++$errors;
}
}
exit !!$errors;