diff --git a/check_source.sh b/check_source.sh index 0056747..cc58657 100755 --- a/check_source.sh +++ b/check_source.sh @@ -6,7 +6,7 @@ bash printinfo.sh make clean > /dev/null echo "checking..." -./helper.pl --check-source --check-makefiles || exit 1 +./helper.pl --check-source --check-makefiles --check-defines|| exit 1 exit 0 diff --git a/helper.pl b/helper.pl index 3b0406d..8088b0e 100755 --- a/helper.pl +++ b/helper.pl @@ -37,11 +37,23 @@ sub check_source { my $content = read_file($file); push @{$troubles->{crlf_line_end}}, '?' if $content =~ /\r/; for my $l (split /\n/, $content) { - push @{$troubles->{merge_conflict}}, $lineno if $l =~ /^(<<<<<<<|=======|>>>>>>>)([^<=>]|$)/; - push @{$troubles->{trailing_space}}, $lineno if $l =~ / $/; - push @{$troubles->{tab}}, $lineno if $l =~ /\t/ && basename($file) !~ /^makefile/i; - push @{$troubles->{non_ascii_char}}, $lineno if $l =~ /[^[:ascii:]]/; - push @{$troubles->{cpp_comment}}, $lineno if $file =~ /\.(c|h)$/ && ($l =~ /\s\/\// || $l =~ /\/\/\s/); + push @{$troubles->{merge_conflict}}, $lineno if $l =~ /^(<<<<<<<|=======|>>>>>>>)([^<=>]|$)/; + push @{$troubles->{trailing_space}}, $lineno if $l =~ / $/; + push @{$troubles->{tab}}, $lineno if $l =~ /\t/ && basename($file) !~ /^makefile/i; + push @{$troubles->{non_ascii_char}}, $lineno if $l =~ /[^[:ascii:]]/; + push @{$troubles->{cpp_comment}}, $lineno if $file =~ /\.(c|h)$/ && ($l =~ /\s\/\// || $l =~ /\/\/\s/); + # in ./src we prefer using XMEMCPY, XMALLOC, XFREE ... + push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcpy\s*\(/; + push @{$troubles->{unwanted_malloc}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmalloc\s*\(/; + push @{$troubles->{unwanted_realloc}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\brealloc\s*\(/; + push @{$troubles->{unwanted_calloc}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bcalloc\s*\(/; + push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bfree\s*\(/; + push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemset\s*\(/; + push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcpy\s*\(/; + push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcmp\s*\(/; + push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrcmp\s*\(/; + push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bclock\s*\(/; + push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bqsort\s*\(/; $lineno++; } for my $k (sort keys %$troubles) { @@ -54,6 +66,21 @@ sub check_source { return $fails; } +sub check_defines { + my $fails = 0; + my $cust_h = read_file("src/headers/tomcrypt_custom.h"); + my $cryp_c = read_file("src/misc/crypt/crypt.c"); + $cust_h =~ s|/\*.*?\*/||sg; # remove comments + $cryp_c =~ s|/\*.*?\*/||sg; # remove comments + my %def = map { $_ => 1 } map { $_ =~ s/^\s*#define\s+(LTC_\S+).*$/$1/; $_ } grep { /^\s*#define\s+LTC_\S+/ } split /\n/, $cust_h; + for my $d (sort keys %def) { + next if $d =~ /^LTC_(DH\d+|ECC\d+|ECC_\S+|MPI|MUTEX_\S+\(x\)|NO_\S+)$/; + warn "$d missing in src/misc/crypt/crypt.c\n" and $fails++ if $cryp_c !~ /\Q$d\E/; + } + warn( $fails > 0 ? "check-defines: FAIL $fails\n" : "check-defines: PASS\n" ); + return $fails; +} + sub prepare_variable { my ($varname, @list) = @_; my $output = "$varname="; @@ -236,6 +263,7 @@ MARKER } GetOptions( "check-source" => \my $check_source, + "check-defines" => \my $check_defines, "check-makefiles" => \my $check_makefiles, "update-makefiles" => \my $update_makefiles, "help" => \my $help @@ -243,6 +271,7 @@ GetOptions( "check-source" => \my $check_source, my $failure; $failure ||= check_source() if $check_source; +$failure ||= check_defines() if $check_defines; $failure ||= process_makefiles(0) if $check_makefiles; $failure ||= process_makefiles(1) if $update_makefiles; diff --git a/makefile b/makefile index 5c2e761..c626339 100644 --- a/makefile +++ b/makefile @@ -397,13 +397,6 @@ zipup: no_oops docs gpg -b -a crypt-$(VERSION).tar.bz2 ; gpg -b -a crypt-$(VERSION).zip ; \ mv -fv crypt* ~ ; rm -rf libtomcrypt-$(VERSION) - -check_defines: - ${silent} cat src/headers/tomcrypt_custom.h | grep '\#define[ \t]*LTC_' | sed -e 's@/\*@@g' -e 's@\*/@@g' -e 's@^[ \t]*@@g' \ - | cut -d' ' -f 2 | sed -e 's@(x)@@g' | sort | uniq \ - | grep -v -e 'LTC_ECC[0-9]*' -e 'LTC_DH[0-9]*' -e 'LTC_NO_' -e 'LTC_MUTEX' -e 'LTC_MPI' \ - | xargs -I '{}' sh -c 'grep -q -m 1 -o {} src/misc/crypt/crypt.c || echo {} not found' - perlcritic: perlcritic *.pl diff --git a/src/encauth/ccm/ccm_memory_ex.c b/src/encauth/ccm/ccm_memory_ex.c index 0fbdd09..1110abb 100644 --- a/src/encauth/ccm/ccm_memory_ex.c +++ b/src/encauth/ccm/ccm_memory_ex.c @@ -360,7 +360,7 @@ if (CTR != NULL) { ctrcopy[z] = (ctrcopy[z] + 1) & 255; if (ctrcopy[z]) break; } - memcpy(CTR, ctrcopy, 16); + XMEMCPY(CTR, ctrcopy, 16); } #ifdef LTC_CLEAN_STACK diff --git a/src/misc/crypt/crypt_constants.c b/src/misc/crypt/crypt_constants.c index 68e9aae..a6b49b7 100755 --- a/src/misc/crypt/crypt_constants.c +++ b/src/misc/crypt/crypt_constants.c @@ -161,7 +161,7 @@ int crypt_get_constant(const char* namein, int *valueout) { int i; int _crypt_constants_len = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]); for (i=0; i<_crypt_constants_len; i++) { - if (strcmp(_crypt_constants[i].name, namein) == 0) { + if (XSTRCMP(_crypt_constants[i].name, namein) == 0) { *valueout = _crypt_constants[i].value; return 0; } diff --git a/src/misc/crypt/crypt_sizes.c b/src/misc/crypt/crypt_sizes.c index 32b04ba..20fbdd1 100755 --- a/src/misc/crypt/crypt_sizes.c +++ b/src/misc/crypt/crypt_sizes.c @@ -248,7 +248,7 @@ int crypt_get_size(const char* namein, unsigned int *sizeout) { int i; int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]); for (i=0; i