In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/b8c77730539d8b2e48e6f7431c34b95ea893926b?hp=4f89f09f9b3db7f542b7029c55aad389a59c9a02>
- Log ----------------------------------------------------------------- commit b8c77730539d8b2e48e6f7431c34b95ea893926b Merge: 4f89f09f9b 686a07f48a Author: Tony Cook <[email protected]> Date: Tue Oct 8 15:55:36 2019 +1100 Disable use of U32_ALIGNMENT_REQUIRED Always assume unaligned access is unsafe. We now always define U32_ALIGNMENT_REQUIRED so that darkpan code that depended on it will use the safer path. ----------------------------------------------------------------------- Summary of changes: AUTHORS | 1 + Configure | 102 ++------------------------------------- Porting/Maintainers.pl | 4 ++ cpan/Digest-MD5/MD5.pm | 2 +- cpan/Digest-MD5/MD5.xs | 44 +---------------- cpan/Digest-MD5/Makefile.PL | 114 -------------------------------------------- cpan/Digest-MD5/t/files.t | 2 +- hv_macro.h | 31 +++++------- stadtx_hash.h | 52 -------------------- t/porting/customized.dat | 2 + zaphod32_hash.h | 35 -------------- 11 files changed, 28 insertions(+), 361 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9f54ea4f36..8fa3f61767 100644 --- a/AUTHORS +++ b/AUTHORS @@ -843,6 +843,7 @@ Matt Kraai <[email protected]> Matt S Trout <[email protected]> Matt Sergeant <[email protected]> Matt Taggart <[email protected]> +Matt Turner <[email protected]> Matthew Black <[email protected]> Matthew Green <[email protected]> Matthew Horsfall <[email protected]> diff --git a/Configure b/Configure index cde374b7d0..fad1c9f2b1 100755 --- a/Configure +++ b/Configure @@ -19705,108 +19705,16 @@ EOM ;; esac -: Checking 32bit alignedness $cat <<EOM Checking to see whether you can access character data unalignedly... -EOM -case "$d_u32align" in -'') $cat >try.c <<EOCP -#include <stdio.h> -#$i_stdlib I_STDLIB -#ifdef I_STDLIB -#include <stdlib.h> -#endif -#define U32 $u32type -#define BYTEORDER 0x$byteorder -#define U8 $u8type -#include <signal.h> -#ifdef SIGBUS -$signal_t bletch(int s) { exit(4); } -#endif -int main() { -#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321 - volatile U8 buf[8]; - volatile U32 *up; - int i; - - if (sizeof(U32) != 4) { - printf("sizeof(U32) is not 4, but %d\n", sizeof(U32)); - exit(1); - } - - fflush(stdout); - -#ifdef SIGBUS - signal(SIGBUS, bletch); -#endif - - buf[0] = 0; - buf[1] = 0; - buf[2] = 0; - buf[3] = 1; - buf[4] = 0; - buf[5] = 0; - buf[6] = 0; - buf[7] = 1; - - for (i = 0; i < 4; i++) { - up = (U32*)(buf + i); - if (! ((*up == 1 << (8*i)) || /* big-endian */ - (*up == 1 << (8*(3-i))) /* little-endian */ - ) - ) - { - printf("read failed (%x)\n", *up); - exit(2); - } - } - - /* write test */ - for (i = 0; i < 4; i++) { - up = (U32*)(buf + i); - *up = 0xBeef; - if (*up != 0xBeef) { - printf("write failed (%x)\n", *up); - exit(3); - } - } - exit(0); -#else - printf("1\n"); - exit(1); -#endif - return 0; -} -EOCP -set try -if eval $compile_ok; then - echo "(Testing for character data alignment may crash the test. That's okay.)" >&4 - $run ./try 2>&1 >/dev/null - case "$?" in - 0) cat >&4 <<EOM -You can access character data pretty unalignedly. -EOM - d_u32align="$undef" - ;; - *) cat >&4 <<EOM -It seems that you must access character data in an aligned manner. +We assume only aligned access is permitted. EOM - d_u32align="$define" - ;; - esac -else - rp='Can you access character data at unaligned addresses?' - dflt='n' - . ./myread - case "$ans" in - [yY]*) d_u32align="$undef" ;; - *) d_u32align="$define" ;; - esac -fi -$rm_try -;; +: Checking 32bit alignedness +: We no longer check and assume it is required. +case "$d_u32align" in +'') d_u32align="$define" ;; esac : see if ualarm exists diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index 4792b6ef1a..9ab84aa0b4 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -373,6 +373,10 @@ use File::Glob qw(:case); 'DISTRIBUTION' => 'GAAS/Digest-MD5-2.55.tar.gz', 'FILES' => q[cpan/Digest-MD5], 'EXCLUDED' => ['rfc1321.txt'], + 'CUSTOMIZED' => [ + # RT #133495 + qw(MD5.xs MD5.pm) + ], }, 'Digest::SHA' => { diff --git a/cpan/Digest-MD5/MD5.pm b/cpan/Digest-MD5/MD5.pm index bc0fec720a..2742a05e65 100644 --- a/cpan/Digest-MD5/MD5.pm +++ b/cpan/Digest-MD5/MD5.pm @@ -3,7 +3,7 @@ package Digest::MD5; use strict; use vars qw($VERSION @ISA @EXPORT_OK); -$VERSION = '2.55'; +$VERSION = '2.55_01'; require Exporter; *import = \&Exporter::import; diff --git a/cpan/Digest-MD5/MD5.xs b/cpan/Digest-MD5/MD5.xs index a48d951056..964d37fb0e 100644 --- a/cpan/Digest-MD5/MD5.xs +++ b/cpan/Digest-MD5/MD5.xs @@ -106,20 +106,6 @@ static MAGIC *THX_sv_magicext(pTHX_ SV *sv, SV *obj, int type, * values. The following macros (and functions) allow us to convert * between native integers and such values. */ -#undef BYTESWAP -#ifndef U32_ALIGNMENT_REQUIRED - #if BYTEORDER == 0x1234 /* 32-bit little endian */ - #define BYTESWAP(x) (x) /* no-op */ - - #elif BYTEORDER == 0x4321 /* 32-bit big endian */ - #define BYTESWAP(x) ((((x)&0xFF)<<24) \ - |(((x)>>24)&0xFF) \ - |(((x)&0x0000FF00)<<8) \ - |(((x)&0x00FF0000)>>8) ) - #endif -#endif - -#ifndef BYTESWAP static void u2s(U32 u, U8* s) { *s++ = (U8)(u & 0xFF); @@ -132,7 +118,6 @@ static void u2s(U32 u, U8* s) ((U32)(*(s+1)) << 8) | \ ((U32)(*(s+2)) << 16) | \ ((U32)(*(s+3)) << 24)) -#endif /* This structure keeps the current state of algorithm. */ @@ -279,29 +264,16 @@ MD5Transform(MD5_CTX* ctx, const U8* buf, STRLEN blocks) U32 C = ctx->C; U32 D = ctx->D; -#ifndef U32_ALIGNMENT_REQUIRED - const U32 *x = (U32*)buf; /* really just type casting */ -#endif - do { U32 a = A; U32 b = B; U32 c = C; U32 d = D; -#if BYTEORDER == 0x1234 && !defined(U32_ALIGNMENT_REQUIRED) - const U32 *X = x; - #define NEXTx (*x++) -#else - U32 X[16]; /* converted values, used in round 2-4 */ + U32 X[16]; /* little-endian values, used in round 2-4 */ U32 *uptr = X; U32 tmp; - #ifdef BYTESWAP - #define NEXTx (tmp=*x++, *uptr++ = BYTESWAP(tmp)) - #else #define NEXTx (s2u(buf,tmp), buf += 4, *uptr++ = tmp) - #endif -#endif #ifdef MD5_DEBUG if (buf == ctx->buffer) @@ -313,7 +285,7 @@ MD5Transform(MD5_CTX* ctx, const U8* buf, STRLEN blocks) int i; fprintf(stderr,"["); for (i = 0; i < 16; i++) { - fprintf(stderr,"%x,", x[i]); + fprintf(stderr,"%x,", x[i]); /* FIXME */ } fprintf(stderr,"]\n"); } @@ -468,30 +440,18 @@ MD5Final(U8* digest, MD5_CTX *ctx) bits_low = ctx->bytes_low << 3; bits_high = (ctx->bytes_high << 3) | (ctx->bytes_low >> 29); -#ifdef BYTESWAP - *(U32*)(ctx->buffer + fill) = BYTESWAP(bits_low); fill += 4; - *(U32*)(ctx->buffer + fill) = BYTESWAP(bits_high); fill += 4; -#else u2s(bits_low, ctx->buffer + fill); fill += 4; u2s(bits_high, ctx->buffer + fill); fill += 4; -#endif MD5Transform(ctx, ctx->buffer, fill >> 6); #ifdef MD5_DEBUG fprintf(stderr," Result: %s\n", ctx_dump(ctx)); #endif -#ifdef BYTESWAP - *(U32*)digest = BYTESWAP(ctx->A); digest += 4; - *(U32*)digest = BYTESWAP(ctx->B); digest += 4; - *(U32*)digest = BYTESWAP(ctx->C); digest += 4; - *(U32*)digest = BYTESWAP(ctx->D); -#else u2s(ctx->A, digest); u2s(ctx->B, digest+4); u2s(ctx->C, digest+8); u2s(ctx->D, digest+12); -#endif } #ifndef INT2PTR diff --git a/cpan/Digest-MD5/Makefile.PL b/cpan/Digest-MD5/Makefile.PL index 1015058bac..76906d1046 100644 --- a/cpan/Digest-MD5/Makefile.PL +++ b/cpan/Digest-MD5/Makefile.PL @@ -5,7 +5,6 @@ use Config qw(%Config); use ExtUtils::MakeMaker; my @extra; -push(@extra, DEFINE => "-DU32_ALIGNMENT_REQUIRED") unless free_u32_alignment(); push(@extra, INSTALLDIRS => 'perl') if $] >= 5.008 && $] < 5.012; if ($^O eq 'VMS') { @@ -39,119 +38,6 @@ WriteMakefile( -sub free_u32_alignment -{ - $|=1; - if (exists $Config{d_u32align}) { - print "Perl's config says that U32 access must "; - print "not " unless $Config{d_u32align}; - print "be aligned.\n"; - return !$Config{d_u32align}; - } - - if ($^O eq 'VMS' || $^O eq 'MSWin32') { - print "Assumes that $^O implies free alignment for U32 access.\n"; - return 1; - } - - if ($^O eq 'hpux' && $Config{osvers} < 11.0) { - print "Will not test for free alignment on older HP-UX.\n"; - return 0; - } - - print "Testing alignment requirements for U32... "; - open(ALIGN_TEST, ">u32align.c") or die "$!"; - print ALIGN_TEST <<'EOT'; close(ALIGN_TEST); -/*--------------------------------------------------------------*/ -/* This program allocates a buffer of U8 (char) and then tries */ -/* to access it through a U32 pointer at every offset. The */ -/* program is expected to die with a bus error/seg fault for */ -/* machines that do not support unaligned integer read/write */ -/*--------------------------------------------------------------*/ - -#include <stdio.h> -#include "EXTERN.h" -#include "perl.h" - -#ifdef printf - #undef printf -#endif - -int main(int argc, char** argv, char** env) -{ -#if BYTEORDER == 0x1234 || BYTEORDER == 0x4321 - volatile U8 buf[] = "\0\0\0\1\0\0\0\0"; - volatile U32 *up; - int i; - - if (sizeof(U32) != 4) { - printf("sizeof(U32) is not 4, but %d\n", sizeof(U32)); - exit(1); - } - - fflush(stdout); - - for (i = 0; i < 4; i++) { - up = (U32*)(buf + i); - if (! ((*up == 1 << (8*i)) || /* big-endian */ - (*up == 1 << (8*(3-i))) /* little-endian */ - ) - ) - { - printf("read failed (%x)\n", *up); - exit(2); - } - } - - /* write test */ - for (i = 0; i < 4; i++) { - up = (U32*)(buf + i); - *up = 0xBeef; - if (*up != 0xBeef) { - printf("write failed (%x)\n", *up); - exit(3); - } - } - - printf("no restrictions\n"); - exit(0); -#else - printf("unusual byteorder, playing safe\n"); - exit(1); -#endif - return 0; -} -/*--------------------------------------------------------------*/ -EOT - - my $cc_cmd = "$Config{cc} $Config{ccflags} -I$Config{archlibexp}/CORE"; - my $exe = "u32align$Config{exe_ext}"; - $cc_cmd .= " -o $exe"; - my $rc; - $rc = system("$cc_cmd $Config{ldflags} u32align.c $Config{libs}"); - if ($rc) { - print "Can't compile test program. Will ensure alignment to play safe.\n\n"; - unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); - return 0; - } - - $rc = system("./$exe"); - unlink("u32align.c", $exe, "u32align$Config{obj_ext}"); - - return 1 unless $rc; - - if ($rc > 0x80) { - (my $cp = $rc) >>= 8; - print "Test program exit status was $cp\n"; - } - if ($rc & 0x80) { - $rc &= ~0x80; - unlink("core") && print "Core dump deleted\n"; - } - print "signal $rc\n" if $rc && $rc < 0x80; - return 0; -} - BEGIN { # compatibility with older versions of MakeMaker my $developer = -d ".git"; diff --git a/cpan/Digest-MD5/t/files.t b/cpan/Digest-MD5/t/files.t index 63479c24a3..ef64088c8c 100644 --- a/cpan/Digest-MD5/t/files.t +++ b/cpan/Digest-MD5/t/files.t @@ -21,7 +21,7 @@ EOT # This is the output of: 'md5sum README MD5.xs rfc1321.txt' $EXPECT = <<EOT; 2f93400875dbb56f36691d5f69f3eba5 README -9572832f3628e3bebcdd54f47c43dc5a MD5.xs +5b8b4f96bc27a425501307c5461970db MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT } diff --git a/hv_macro.h b/hv_macro.h index 77a4c84896..02c0baad08 100644 --- a/hv_macro.h +++ b/hv_macro.h @@ -6,7 +6,7 @@ #endif /*----------------------------------------------------------------------------- - * Endianess, misalignment capabilities and util macros + * Endianess and util macros * * The following 3 macros are defined in this section. The other macros defined * are only needed to help derive these 3. @@ -20,29 +20,22 @@ * ROTR64(x,r) Rotate x right by r bits */ -#ifndef U32_ALIGNMENT_REQUIRED +#ifndef U8TO16_LE #if (BYTEORDER == 0x1234 || BYTEORDER == 0x12345678) - #define U8TO16_LE(ptr) (*((const U16*)(ptr))) - #define U8TO32_LE(ptr) (*((const U32*)(ptr))) - #define U8TO64_LE(ptr) (*((const U64*)(ptr))) + #define U8TO16_LE(ptr) ((U32)(ptr)[1]|(U32)(ptr)[0]<<8) + #define U8TO32_LE(ptr) ((U32)(ptr)[3]|(U32)(ptr)[2]<<8|(U32)(ptr)[1]<<16|(U32)(ptr)[0]<<24) + #define U8TO64_LE(ptr) ((U64)(ptr)[7]|(U64)(ptr)[6]<<8|(U64)(ptr)[5]<<16|(U64)(ptr)[4]<<24|\ + (U64)(ptr)[3]<<32|(U64)(ptr)[4]<<40|\ + (U64)(ptr)[1]<<48|(U64)(ptr)[0]<<56) #elif (BYTEORDER == 0x4321 || BYTEORDER == 0x87654321) - #if defined(__GNUC__) && (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=3)) - #define U8TO16_LE(ptr) (__builtin_bswap16(*((U16*)(ptr)))) - #define U8TO32_LE(ptr) (__builtin_bswap32(*((U32*)(ptr)))) - #define U8TO64_LE(ptr) (__builtin_bswap64(*((U64*)(ptr)))) - #endif + #define U8TO16_LE(ptr) ((U32)(ptr)[0]|(U32)(ptr)[1]<<8) + #define U8TO32_LE(ptr) ((U32)(ptr)[0]|(U32)(ptr)[1]<<8|(U32)(ptr)[2]<<16|(U32)(ptr)[3]<<24) + #define U8TO64_LE(ptr) ((U64)(ptr)[0]|(U64)(ptr)[1]<<8|(U64)(ptr)[2]<<16|(U64)(ptr)[3]<<24|\ + (U64)(ptr)[4]<<32|(U64)(ptr)[5]<<40|\ + (U64)(ptr)[6]<<48|(U64)(ptr)[7]<<56) #endif #endif -#ifndef U8TO16_LE - /* Without a known fast bswap32 we're just as well off doing this */ - #define U8TO16_LE(ptr) ((U32)(ptr)[0]|(U32)(ptr)[1]<<8) - #define U8TO32_LE(ptr) ((U32)(ptr)[0]|(U32)(ptr)[1]<<8|(U32)(ptr)[2]<<16|(U32)(ptr)[3]<<24) - #define U8TO64_LE(ptr) ((U64)(ptr)[0]|(U64)(ptr)[1]<<8|(U64)(ptr)[2]<<16|(U64)(ptr)[3]<<24|\ - (U64)(ptr)[4]<<32|(U64)(ptr)[5]<<40|\ - (U64)(ptr)[6]<<48|(U64)(ptr)[7]<<56) -#endif - #ifdef CAN64BITHASH #ifndef U64TYPE /* This probably isn't going to work, but failing with a compiler error due to diff --git a/stadtx_hash.h b/stadtx_hash.h index bd09c2f938..5ee879485d 100644 --- a/stadtx_hash.h +++ b/stadtx_hash.h @@ -43,58 +43,6 @@ #define STMT_END while(0) #endif -#ifndef STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -/* STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN only matters if nothing has defined U8TO64_LE etc, - * and when built with Perl these should be defined before this file is loaded. - */ -#ifdef U32_ALIGNMENT_REQUIRED -#define STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN 0 -#else -#define STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN 1 -#endif -#endif - -#ifndef U8TO64_LE -#if STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -#define U8TO64_LE(ptr) (*((const U64 *)(ptr))) -#else -#define U8TO64_LE(ptr) (\ - (U64)(ptr)[7] << 56 | \ - (U64)(ptr)[6] << 48 | \ - (U64)(ptr)[5] << 40 | \ - (U64)(ptr)[4] << 32 | \ - (U64)(ptr)[3] << 24 | \ - (U64)(ptr)[2] << 16 | \ - (U64)(ptr)[1] << 8 | \ - (U64)(ptr)[0] \ -) -#endif -#endif - -#ifndef U8TO32_LE -#if STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -#define U8TO32_LE(ptr) (*((const U32 *)(ptr))) -#else -#define U8TO32_LE(ptr) (\ - (U32)(ptr)[3] << 24 | \ - (U32)(ptr)[2] << 16 | \ - (U32)(ptr)[1] << 8 | \ - (U32)(ptr)[0] \ -) -#endif -#endif - -#ifndef U8TO16_LE -#if STADTX_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -#define U8TO16_LE(ptr) (*((const U16 *)(ptr))) -#else -#define U8TO16_LE(ptr) (\ - (U16)(ptr)[1] << 8 | \ - (U16)(ptr)[0] \ -) -#endif -#endif - /* Find best way to ROTL32/ROTL64 */ #if defined(_MSC_VER) #include <stdlib.h> /* Microsoft put _rotl declaration in here */ diff --git a/t/porting/customized.dat b/t/porting/customized.dat index b386353b7c..1d8af916c8 100644 --- a/t/porting/customized.dat +++ b/t/porting/customized.dat @@ -3,6 +3,8 @@ # ./perl -I../lib porting/customized.t --regen Config::Perl::V cpan/Config-Perl-V/V.pm 0a0f7207e6505b78ee345a933acb0246a13579f5 Digest cpan/Digest/Digest.pm 43f7f544cb11842b2f55c73e28930da50774e081 +Digest::MD5 cpan/Digest-MD5/MD5.pm df5f0663f0f755be7eda6e3d2f008f2629246b19 +Digest::MD5 cpan/Digest-MD5/MD5.xs 249bed648232192ce018f7f894ad127c3a639831 Locale::Maketext::Simple cpan/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm 57ed38905791a17c150210cd6f42ead22a7707b6 Math::Complex cpan/Math-Complex/lib/Math/Complex.pm 198ea6c6c584f5ea79a0fd7e9d411d0878f3b2af Math::Complex cpan/Math-Complex/t/Complex.t 4f307ed6fc59f1e5fb0e6b11103fc631b6bdb335 diff --git a/zaphod32_hash.h b/zaphod32_hash.h index c9b60ccb32..2fb391a233 100644 --- a/zaphod32_hash.h +++ b/zaphod32_hash.h @@ -74,41 +74,6 @@ #define STMT_END while(0) #endif -#ifndef ZAPHOD32_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -/* ZAPHOD32_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN only matters if nothing has defined U8TO64_LE etc, - * and when built with Perl these should be defined before this file is loaded. - */ -#ifdef U32_ALIGNMENT_REQUIRED -#define ZAPHOD32_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN 0 -#else -#define ZAPHOD32_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN 1 -#endif -#endif - -#ifndef U8TO32_LE -#if ZAPHOD32_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -#define U8TO32_LE(ptr) (*((const U32 *)(ptr))) -#else -#define U8TO32_LE(ptr) (\ - (U32)(ptr)[3] << 24 | \ - (U32)(ptr)[2] << 16 | \ - (U32)(ptr)[1] << 8 | \ - (U32)(ptr)[0] \ -) -#endif -#endif - -#ifndef U8TO16_LE -#if ZAPHOD32_ALLOW_UNALIGNED_AND_LITTLE_ENDIAN -#define U8TO16_LE(ptr) (*((const U16 *)(ptr))) -#else -#define U8TO16_LE(ptr) (\ - (U16)(ptr)[1] << 8 | \ - (U16)(ptr)[0] \ -) -#endif -#endif - /* This is two marsaglia xor-shift permutes, with a prime-multiple * sandwiched inside. The end result of doing this twice with different * primes is a completely avalanched v. */ -- Perl5 Master Repository
