diff options
Diffstat (limited to 'gnu/usr.bin/perl/cpan')
20 files changed, 757 insertions, 671 deletions
diff --git a/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm b/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm index 47aebd60743..9d7e5ed262d 100644 --- a/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm +++ b/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm @@ -35,7 +35,8 @@ sub MY::libscan my $path = shift; return undef - if $path =~ /(~|\.bak|_bak)$/ || + if $path =~ /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/ || + $path =~ /(~|\.bak|_bak)$/ || $path =~ /\..*\.sw(o|p)$/ || $path =~ /\B\.svn\b/; diff --git a/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm b/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm index 47aebd60743..9d7e5ed262d 100644 --- a/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm +++ b/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm @@ -35,7 +35,8 @@ sub MY::libscan my $path = shift; return undef - if $path =~ /(~|\.bak|_bak)$/ || + if $path =~ /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/ || + $path =~ /(~|\.bak|_bak)$/ || $path =~ /\..*\.sw(o|p)$/ || $path =~ /\B\.svn\b/; diff --git a/gnu/usr.bin/perl/cpan/Digest-MD5/MD5.xs b/gnu/usr.bin/perl/cpan/Digest-MD5/MD5.xs index acefc30711e..d8b156370f6 100644 --- a/gnu/usr.bin/perl/cpan/Digest-MD5/MD5.xs +++ b/gnu/usr.bin/perl/cpan/Digest-MD5/MD5.xs @@ -39,6 +39,8 @@ extern "C" { #include "EXTERN.h" #include "perl.h" #include "XSUB.h" +#include <sys/types.h> +#include <md5.h> #ifdef __cplusplus } #endif @@ -88,61 +90,6 @@ static MAGIC *THX_sv_magicext(pTHX_ SV *sv, SV *obj, int type, # define SvPVbyte(sv, lp) (sv_utf8_downgrade((sv), 0), SvPV((sv), (lp))) #endif -/* Perl does not guarantee that U32 is exactly 32 bits. Some system - * has no integral type with exactly 32 bits. For instance, A Cray has - * short, int and long all at 64 bits so we need to apply this macro - * to reduce U32 values to 32 bits at appropriate places. If U32 - * really does have 32 bits then this is a no-op. - */ -#if BYTEORDER > 0x4321 || defined(TRUNCATE_U32) - #define TO32(x) ((x) & 0xFFFFffff) - #define TRUNC32(x) ((x) &= 0xFFFFffff) -#else - #define TO32(x) (x) - #define TRUNC32(x) /*nothing*/ -#endif - -/* The MD5 algorithm is defined in terms of little endian 32-bit - * 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); - *s++ = (U8)((u >> 8) & 0xFF); - *s++ = (U8)((u >> 16) & 0xFF); - *s = (U8)((u >> 24) & 0xFF); -} - -#define s2u(s,u) ((u) = (U32)(*s) | \ - ((U32)(*(s+1)) << 8) | \ - ((U32)(*(s+2)) << 16) | \ - ((U32)(*(s+3)) << 24)) -#endif - -/* This structure keeps the current state of algorithm. - */ -typedef struct { - U32 A, B, C, D; /* current digest */ - U32 bytes_low; /* counts bytes in message */ - U32 bytes_high; /* turn it into a 64-bit counter */ - U8 buffer[128]; /* collect complete 64 byte blocks */ -} MD5_CTX; - #if defined(USE_ITHREADS) && defined(MGf_DUP) STATIC int dup_md5_ctx(pTHX_ MAGIC *mg, CLONE_PARAMS *params) { @@ -179,325 +126,6 @@ const STATIC struct { }; #endif - -/* Padding is added at the end of the message in order to fill a - * complete 64 byte block (- 8 bytes for the message length). The - * padding is also the reason the buffer in MD5_CTX have to be - * 128 bytes. - */ -static const unsigned char PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* Constants for MD5Transform routine. - */ -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -/* F, G, H and I are basic MD5 functions. - */ -#define F(x, y, z) ((((x) & ((y) ^ (z))) ^ (z))) -#define G(x, y, z) F(z, x, y) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define I(x, y, z) ((y) ^ ((x) | (~z))) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n) | ((x) >> (32-(n))))) - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - * Rotation is separate from addition to prevent recomputation. - */ -#define FF(a, b, c, d, s, ac) \ - (a) += F ((b), (c), (d)) + (NEXTx) + (U32)(ac); \ - TRUNC32((a)); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - TRUNC32((a)); - -#define GG(a, b, c, d, x, s, ac) \ - (a) += G ((b), (c), (d)) + X[x] + (U32)(ac); \ - TRUNC32((a)); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - TRUNC32((a)); - -#define HH(a, b, c, d, x, s, ac) \ - (a) += H ((b), (c), (d)) + X[x] + (U32)(ac); \ - TRUNC32((a)); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - TRUNC32((a)); - -#define II(a, b, c, d, x, s, ac) \ - (a) += I ((b), (c), (d)) + X[x] + (U32)(ac); \ - TRUNC32((a)); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - TRUNC32((a)); - - -static void -MD5Init(MD5_CTX *ctx) -{ - /* Start state */ - ctx->A = 0x67452301; - ctx->B = 0xefcdab89; - ctx->C = 0x98badcfe; - ctx->D = 0x10325476; - - /* message length */ - ctx->bytes_low = ctx->bytes_high = 0; -} - - -static void -MD5Transform(MD5_CTX* ctx, const U8* buf, STRLEN blocks) -{ -#ifdef MD5_DEBUG - static int tcount = 0; -#endif - - U32 A = ctx->A; - U32 B = ctx->B; - 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 *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) - fprintf(stderr,"%5d: Transform ctx->buffer", ++tcount); - else - fprintf(stderr,"%5d: Transform %p (%d)", ++tcount, buf, blocks); - - { - int i; - fprintf(stderr,"["); - for (i = 0; i < 16; i++) { - fprintf(stderr,"%x,", x[i]); - } - fprintf(stderr,"]\n"); - } -#endif - - /* Round 1 */ - FF (a, b, c, d, S11, 0xd76aa478); /* 1 */ - FF (d, a, b, c, S12, 0xe8c7b756); /* 2 */ - FF (c, d, a, b, S13, 0x242070db); /* 3 */ - FF (b, c, d, a, S14, 0xc1bdceee); /* 4 */ - FF (a, b, c, d, S11, 0xf57c0faf); /* 5 */ - FF (d, a, b, c, S12, 0x4787c62a); /* 6 */ - FF (c, d, a, b, S13, 0xa8304613); /* 7 */ - FF (b, c, d, a, S14, 0xfd469501); /* 8 */ - FF (a, b, c, d, S11, 0x698098d8); /* 9 */ - FF (d, a, b, c, S12, 0x8b44f7af); /* 10 */ - FF (c, d, a, b, S13, 0xffff5bb1); /* 11 */ - FF (b, c, d, a, S14, 0x895cd7be); /* 12 */ - FF (a, b, c, d, S11, 0x6b901122); /* 13 */ - FF (d, a, b, c, S12, 0xfd987193); /* 14 */ - FF (c, d, a, b, S13, 0xa679438e); /* 15 */ - FF (b, c, d, a, S14, 0x49b40821); /* 16 */ - - /* Round 2 */ - GG (a, b, c, d, 1, S21, 0xf61e2562); /* 17 */ - GG (d, a, b, c, 6, S22, 0xc040b340); /* 18 */ - GG (c, d, a, b, 11, S23, 0x265e5a51); /* 19 */ - GG (b, c, d, a, 0, S24, 0xe9b6c7aa); /* 20 */ - GG (a, b, c, d, 5, S21, 0xd62f105d); /* 21 */ - GG (d, a, b, c, 10, S22, 0x2441453); /* 22 */ - GG (c, d, a, b, 15, S23, 0xd8a1e681); /* 23 */ - GG (b, c, d, a, 4, S24, 0xe7d3fbc8); /* 24 */ - GG (a, b, c, d, 9, S21, 0x21e1cde6); /* 25 */ - GG (d, a, b, c, 14, S22, 0xc33707d6); /* 26 */ - GG (c, d, a, b, 3, S23, 0xf4d50d87); /* 27 */ - GG (b, c, d, a, 8, S24, 0x455a14ed); /* 28 */ - GG (a, b, c, d, 13, S21, 0xa9e3e905); /* 29 */ - GG (d, a, b, c, 2, S22, 0xfcefa3f8); /* 30 */ - GG (c, d, a, b, 7, S23, 0x676f02d9); /* 31 */ - GG (b, c, d, a, 12, S24, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ - HH (a, b, c, d, 5, S31, 0xfffa3942); /* 33 */ - HH (d, a, b, c, 8, S32, 0x8771f681); /* 34 */ - HH (c, d, a, b, 11, S33, 0x6d9d6122); /* 35 */ - HH (b, c, d, a, 14, S34, 0xfde5380c); /* 36 */ - HH (a, b, c, d, 1, S31, 0xa4beea44); /* 37 */ - HH (d, a, b, c, 4, S32, 0x4bdecfa9); /* 38 */ - HH (c, d, a, b, 7, S33, 0xf6bb4b60); /* 39 */ - HH (b, c, d, a, 10, S34, 0xbebfbc70); /* 40 */ - HH (a, b, c, d, 13, S31, 0x289b7ec6); /* 41 */ - HH (d, a, b, c, 0, S32, 0xeaa127fa); /* 42 */ - HH (c, d, a, b, 3, S33, 0xd4ef3085); /* 43 */ - HH (b, c, d, a, 6, S34, 0x4881d05); /* 44 */ - HH (a, b, c, d, 9, S31, 0xd9d4d039); /* 45 */ - HH (d, a, b, c, 12, S32, 0xe6db99e5); /* 46 */ - HH (c, d, a, b, 15, S33, 0x1fa27cf8); /* 47 */ - HH (b, c, d, a, 2, S34, 0xc4ac5665); /* 48 */ - - /* Round 4 */ - II (a, b, c, d, 0, S41, 0xf4292244); /* 49 */ - II (d, a, b, c, 7, S42, 0x432aff97); /* 50 */ - II (c, d, a, b, 14, S43, 0xab9423a7); /* 51 */ - II (b, c, d, a, 5, S44, 0xfc93a039); /* 52 */ - II (a, b, c, d, 12, S41, 0x655b59c3); /* 53 */ - II (d, a, b, c, 3, S42, 0x8f0ccc92); /* 54 */ - II (c, d, a, b, 10, S43, 0xffeff47d); /* 55 */ - II (b, c, d, a, 1, S44, 0x85845dd1); /* 56 */ - II (a, b, c, d, 8, S41, 0x6fa87e4f); /* 57 */ - II (d, a, b, c, 15, S42, 0xfe2ce6e0); /* 58 */ - II (c, d, a, b, 6, S43, 0xa3014314); /* 59 */ - II (b, c, d, a, 13, S44, 0x4e0811a1); /* 60 */ - II (a, b, c, d, 4, S41, 0xf7537e82); /* 61 */ - II (d, a, b, c, 11, S42, 0xbd3af235); /* 62 */ - II (c, d, a, b, 2, S43, 0x2ad7d2bb); /* 63 */ - II (b, c, d, a, 9, S44, 0xeb86d391); /* 64 */ - - A += a; TRUNC32(A); - B += b; TRUNC32(B); - C += c; TRUNC32(C); - D += d; TRUNC32(D); - - } while (--blocks); - ctx->A = A; - ctx->B = B; - ctx->C = C; - ctx->D = D; -} - - -#ifdef MD5_DEBUG -static char* -ctx_dump(MD5_CTX* ctx) -{ - static char buf[1024]; - sprintf(buf, "{A=%x,B=%x,C=%x,D=%x,%d,%d(%d)}", - ctx->A, ctx->B, ctx->C, ctx->D, - ctx->bytes_low, ctx->bytes_high, (ctx->bytes_low&0x3F)); - return buf; -} -#endif - - -static void -MD5Update(MD5_CTX* ctx, const U8* buf, STRLEN len) -{ - STRLEN blocks; - STRLEN fill = ctx->bytes_low & 0x3F; - -#ifdef MD5_DEBUG - static int ucount = 0; - fprintf(stderr,"%5i: Update(%s, %p, %d)\n", ++ucount, ctx_dump(ctx), - buf, len); -#endif - - ctx->bytes_low += len; - if (ctx->bytes_low < len) /* wrap around */ - ctx->bytes_high++; - - if (fill) { - STRLEN missing = 64 - fill; - if (len < missing) { - Copy(buf, ctx->buffer + fill, len, U8); - return; - } - Copy(buf, ctx->buffer + fill, missing, U8); - MD5Transform(ctx, ctx->buffer, 1); - buf += missing; - len -= missing; - } - - blocks = len >> 6; - if (blocks) - MD5Transform(ctx, buf, blocks); - if ( (len &= 0x3F)) { - Copy(buf + (blocks << 6), ctx->buffer, len, U8); - } -} - - -static void -MD5Final(U8* digest, MD5_CTX *ctx) -{ - STRLEN fill = ctx->bytes_low & 0x3F; - STRLEN padlen = (fill < 56 ? 56 : 120) - fill; - U32 bits_low, bits_high; -#ifdef MD5_DEBUG - fprintf(stderr," Final: %s\n", ctx_dump(ctx)); -#endif - Copy(PADDING, ctx->buffer + fill, padlen, U8); - fill += padlen; - - 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 -#define INT2PTR(any,d) (any)(d) -#endif - static MD5_CTX* get_md5_ctx(pTHX_ SV* sv) { MAGIC *mg; @@ -678,7 +306,7 @@ addfile(self, fh) InputStream fh PREINIT: MD5_CTX* context = get_md5_ctx(aTHX_ self); - STRLEN fill = context->bytes_low & 0x3F; + STRLEN fill = (context->count >> 3) & (MD5_BLOCK_LENGTH - 1); #ifdef USE_HEAP_INSTEAD_OF_STACK unsigned char* buffer; #else @@ -743,14 +371,12 @@ context(ctx, ...) PPCODE: if (items > 2) { STRLEN len; - unsigned long blocks = SvUV(ST(1)); + ctx->count = SvUV(ST(1)) << 3; unsigned char *buf = (unsigned char *)(SvPV(ST(2), len)); - ctx->A = buf[ 0] | (buf[ 1]<<8) | (buf[ 2]<<16) | (buf[ 3]<<24); - ctx->B = buf[ 4] | (buf[ 5]<<8) | (buf[ 6]<<16) | (buf[ 7]<<24); - ctx->C = buf[ 8] | (buf[ 9]<<8) | (buf[10]<<16) | (buf[11]<<24); - ctx->D = buf[12] | (buf[13]<<8) | (buf[14]<<16) | (buf[15]<<24); - ctx->bytes_low = blocks << 6; - ctx->bytes_high = blocks >> 26; + ctx->state[0] = buf[ 0] | (buf[ 1]<<8) | (buf[ 2]<<16) | (buf[ 3]<<24); + ctx->state[1] = buf[ 4] | (buf[ 5]<<8) | (buf[ 6]<<16) | (buf[ 7]<<24); + ctx->state[2] = buf[ 8] | (buf[ 9]<<8) | (buf[10]<<16) | (buf[11]<<24); + ctx->state[3] = buf[12] | (buf[13]<<8) | (buf[14]<<16) | (buf[15]<<24); if (items == 4) { buf = (unsigned char *)(SvPV(ST(3), len)); MD5Update(ctx, buf, len); @@ -760,17 +386,20 @@ context(ctx, ...) XSRETURN(0); } - w=ctx->A; out[ 0]=w; out[ 1]=(w>>8); out[ 2]=(w>>16); out[ 3]=(w>>24); - w=ctx->B; out[ 4]=w; out[ 5]=(w>>8); out[ 6]=(w>>16); out[ 7]=(w>>24); - w=ctx->C; out[ 8]=w; out[ 9]=(w>>8); out[10]=(w>>16); out[11]=(w>>24); - w=ctx->D; out[12]=w; out[13]=(w>>8); out[14]=(w>>16); out[15]=(w>>24); + w=ctx->state[0]; out[ 0]=w; out[ 1]=(w>>8); out[ 2]=(w>>16); out[ 3]=(w>>24); + w=ctx->state[1]; out[ 4]=w; out[ 5]=(w>>8); out[ 6]=(w>>16); out[ 7]=(w>>24); + w=ctx->state[2]; out[ 8]=w; out[ 9]=(w>>8); out[10]=(w>>16); out[11]=(w>>24); + w=ctx->state[3]; out[12]=w; out[13]=(w>>8); out[14]=(w>>16); out[15]=(w>>24); EXTEND(SP, 3); - ST(0) = sv_2mortal(newSVuv(ctx->bytes_high << 26 | - ctx->bytes_low >> 6)); + ST(0) = sv_2mortal(newSViv((ctx->count >> 3) + - ((ctx->count >> 3) % MD5_BLOCK_LENGTH))); ST(1) = sv_2mortal(newSVpv(out, 16)); - ST(2) = sv_2mortal(newSVpv((char *)ctx->buffer, - ctx->bytes_low & 0x3F)); + ST(2) = sv_2mortal(newSVpv("",0)); + if (((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)) != 0) + ST(2) = sv_2mortal(newSVpv((char *)ctx->buffer, + (ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1))); + XSRETURN(3); void diff --git a/gnu/usr.bin/perl/cpan/Digest-MD5/t/files.t b/gnu/usr.bin/perl/cpan/Digest-MD5/t/files.t index d6b4fcb2cd7..14a39925707 100755 --- a/gnu/usr.bin/perl/cpan/Digest-MD5/t/files.t +++ b/gnu/usr.bin/perl/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 -0a0cf2512d18d24c6881d7d755e2b609 MD5.xs +5457ac1c3f0f33df96437555dc7eb172 MD5.xs 754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt EOT } diff --git a/gnu/usr.bin/perl/cpan/ExtUtils-Install/lib/ExtUtils/Install.pm b/gnu/usr.bin/perl/cpan/ExtUtils-Install/lib/ExtUtils/Install.pm index 1e8ac4cd12b..1b98c4321e2 100644 --- a/gnu/usr.bin/perl/cpan/ExtUtils-Install/lib/ExtUtils/Install.pm +++ b/gnu/usr.bin/perl/cpan/ExtUtils-Install/lib/ExtUtils/Install.pm @@ -100,6 +100,7 @@ my $Is_MacPerl = $^O eq 'MacOS'; my $Is_Win32 = $^O eq 'MSWin32'; my $Is_cygwin = $^O eq 'cygwin'; my $CanMoveAtBoot = ($Is_Win32 || $Is_cygwin); +my $Perm_Dir = $ENV{PERL_CORE} ? 0770 : 0755; # *note* CanMoveAtBoot is only incidentally the same condition as below # this needs not hold true in the future. @@ -783,7 +784,7 @@ sub install { #XXX OS-SPECIFIC _chdir($cwd); } foreach my $targetdir (sort keys %check_dirs) { - _mkpath( $targetdir, 0, 0755, $verbose, $dry_run ); + _mkpath( $targetdir, 0, $Perm_Dir, $verbose, $dry_run ); } foreach my $found (@found_files) { my ($diff, $ffd, $origfile, $mode, $size, $atime, $mtime, @@ -797,7 +798,7 @@ sub install { #XXX OS-SPECIFIC $targetfile= _unlink_or_rename( $targetfile, 'tryhard', 'install' ) unless $dry_run; } elsif ( ! -d $targetdir ) { - _mkpath( $targetdir, 0, 0755, $verbose, $dry_run ); + _mkpath( $targetdir, 0, $Perm_Dir, $verbose, $dry_run ); } print "Installing $targetfile\n"; @@ -837,7 +838,7 @@ sub install { #XXX OS-SPECIFIC if ($pack{'write'}) { $dir = install_rooted_dir(dirname($pack{'write'})); - _mkpath( $dir, 0, 0755, $verbose, $dry_run ); + _mkpath( $dir, 0, $Perm_Dir, $verbose, $dry_run ); print "Writing $pack{'write'}\n" if $verbose; $packlist->write(install_rooted_file($pack{'write'})) unless $dry_run; } @@ -1180,7 +1181,7 @@ environment variable will silence this output. sub pm_to_blib { my($fromto,$autodir,$pm_filter) = @_; - _mkpath($autodir,0,0755); + _mkpath($autodir,0,$Perm_Dir); while(my($from, $to) = each %$fromto) { if( -f $to && -s $from == -s $to && -M $to < -M $from ) { print "Skip $to (unchanged)\n" unless $INSTALL_QUIET; @@ -1203,7 +1204,7 @@ sub pm_to_blib { # we wont try hard here. its too likely to mess things up. forceunlink($to); } else { - _mkpath(dirname($to),0,0755); + _mkpath(dirname($to),0,$Perm_Dir); } if ($need_filtering) { run_filter($pm_filter, $from, $to); diff --git a/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm b/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm index 009b18ee085..785daaaed32 100644 --- a/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm +++ b/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm @@ -933,7 +933,7 @@ OTHERLDFLAGS = '.$ld_opt.$otherldflags.' INST_DYNAMIC_DEP = '.$inst_dynamic_dep.' INST_DYNAMIC_FIX = '.$ld_fix.' -$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP) +$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP) '); if ($armaybe ne ':'){ $ldfrom = 'tmp$(LIB_EXT)'; @@ -985,7 +985,7 @@ MAKE push @m, <<'MAKE'; $(CHMOD) $(PERM_RWX) $@ - $(NOECHO) $(RM_RF) $(BOOTSTRAP) + $(NOECHO) $(RM_RF) $(INST_BOOT) - $(CP_NONEMPTY) $(BOOTSTRAP) $(INST_BOOT) $(PERM_RW) MAKE @@ -2049,7 +2049,8 @@ Called by init_main. Initializes PERL_* sub init_PERM { my($self) = shift; - $self->{PERM_DIR} = 755 unless defined $self->{PERM_DIR}; + my $perm_dir = $self->{PERL_CORE} ? 770 : 755; + $self->{PERM_DIR} = $perm_dir unless defined $self->{PERM_DIR}; $self->{PERM_RW} = 644 unless defined $self->{PERM_RW}; $self->{PERM_RWX} = 755 unless defined $self->{PERM_RWX}; diff --git a/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/eu_command.t b/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/eu_command.t index 269aa5c9a4c..32a6f59dcab 100644 --- a/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/eu_command.t +++ b/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/eu_command.t @@ -151,20 +151,21 @@ BEGIN { is( ((stat('testdir'))[2] & 07777) & 0700, 0100, 'change a dir to execute-only' ); - # change a dir to read-only - @ARGV = ( '0400', 'testdir' ); + # change a dir to write-only + @ARGV = ( '0200', 'testdir' ); ExtUtils::Command::chmod(); is( ((stat('testdir'))[2] & 07777) & 0700, - 0400, 'change a dir to read-only' ); + 0200, 'change a dir to write-only' ); - # change a dir to write-only - @ARGV = ( '0200', 'testdir' ); + # change a dir to read-only + @ARGV = ( '0400', 'testdir' ); ExtUtils::Command::chmod(); is( ((stat('testdir'))[2] & 07777) & 0700, - 0200, 'change a dir to write-only' ); + 0400, 'change a dir to read-only' ); + # remove the dir we've been playing with @ARGV = ('testdir'); rm_rf; ok( ! -e 'testdir', 'rm_rf can delete a read-only dir' ); diff --git a/gnu/usr.bin/perl/cpan/File-Path/lib/File/Path.pm b/gnu/usr.bin/perl/cpan/File-Path/lib/File/Path.pm index 034da1e578d..138bdc24ffb 100644 --- a/gnu/usr.bin/perl/cpan/File-Path/lib/File/Path.pm +++ b/gnu/usr.bin/perl/cpan/File-Path/lib/File/Path.pm @@ -18,7 +18,7 @@ BEGIN { use Exporter (); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); -$VERSION = '2.12_01'; +$VERSION = '2.13'; $VERSION = eval $VERSION; @ISA = qw(Exporter); @EXPORT = qw(mkpath rmtree); @@ -85,15 +85,15 @@ sub make_path { sub mkpath { my $old_style = !( @_ and __is_arg( $_[-1] ) ); - my $arg; + my $data; my $paths; if ($old_style) { my ( $verbose, $mode ); ( $paths, $verbose, $mode ) = @_; $paths = [$paths] unless UNIVERSAL::isa( $paths, 'ARRAY' ); - $arg->{verbose} = $verbose; - $arg->{mode} = defined $mode ? $mode : oct '777'; + $data->{verbose} = $verbose; + $data->{mode} = defined $mode ? $mode : oct '777'; } else { my %args_permitted = map { $_ => 1 } ( qw| @@ -107,55 +107,74 @@ sub mkpath { user verbose | ); + my %not_on_win32_args = map { $_ => 1 } ( qw| + group + owner + uid + user + | ); my @bad_args = (); - $arg = pop @_; + my @win32_implausible_args = (); + my $arg = pop @_; for my $k (sort keys %{$arg}) { - push @bad_args, $k unless $args_permitted{$k}; - } - _carp("Unrecognized option(s) passed to make_path(): @bad_args") - if @bad_args; - $arg->{mode} = delete $arg->{mask} if exists $arg->{mask}; - $arg->{mode} = oct '777' unless exists $arg->{mode}; - ${ $arg->{error} } = [] if exists $arg->{error}; - $arg->{owner} = delete $arg->{user} if exists $arg->{user}; - $arg->{owner} = delete $arg->{uid} if exists $arg->{uid}; - if ( exists $arg->{owner} and $arg->{owner} =~ /\D/ ) { - my $uid = ( getpwnam $arg->{owner} )[2]; - if ( defined $uid ) { - $arg->{owner} = $uid; + if (! $args_permitted{$k}) { + push @bad_args, $k; + } + elsif ($not_on_win32_args{$k} and _IS_MSWIN32) { + push @win32_implausible_args, $k; } else { - _error( $arg, -"unable to map $arg->{owner} to a uid, ownership not changed" - ); - delete $arg->{owner}; + $data->{$k} = $arg->{$k}; } } - if ( exists $arg->{group} and $arg->{group} =~ /\D/ ) { - my $gid = ( getgrnam $arg->{group} )[2]; - if ( defined $gid ) { - $arg->{group} = $gid; + _carp("Unrecognized option(s) passed to mkpath() or make_path(): @bad_args") + if @bad_args; + _carp("Option(s) implausible on Win32 passed to mkpath() or make_path(): @win32_implausible_args") + if @win32_implausible_args; + $data->{mode} = delete $data->{mask} if exists $data->{mask}; + $data->{mode} = oct '777' unless exists $data->{mode}; + ${ $data->{error} } = [] if exists $data->{error}; + unless (@win32_implausible_args) { + $data->{owner} = delete $data->{user} if exists $data->{user}; + $data->{owner} = delete $data->{uid} if exists $data->{uid}; + if ( exists $data->{owner} and $data->{owner} =~ /\D/ ) { + my $uid = ( getpwnam $data->{owner} )[2]; + if ( defined $uid ) { + $data->{owner} = $uid; + } + else { + _error( $data, + "unable to map $data->{owner} to a uid, ownership not changed" + ); + delete $data->{owner}; + } } - else { - _error( $arg, -"unable to map $arg->{group} to a gid, group ownership not changed" - ); - delete $arg->{group}; + if ( exists $data->{group} and $data->{group} =~ /\D/ ) { + my $gid = ( getgrnam $data->{group} )[2]; + if ( defined $gid ) { + $data->{group} = $gid; + } + else { + _error( $data, + "unable to map $data->{group} to a gid, group ownership not changed" + ); + delete $data->{group}; + } + } + if ( exists $data->{owner} and not exists $data->{group} ) { + $data->{group} = -1; # chown will leave group unchanged + } + if ( exists $data->{group} and not exists $data->{owner} ) { + $data->{owner} = -1; # chown will leave owner unchanged } - } - if ( exists $arg->{owner} and not exists $arg->{group} ) { - $arg->{group} = -1; # chown will leave group unchanged - } - if ( exists $arg->{group} and not exists $arg->{owner} ) { - $arg->{owner} = -1; # chown will leave owner unchanged } $paths = [@_]; } - return _mkpath( $arg, $paths ); + return _mkpath( $data, $paths ); } sub _mkpath { - my $arg = shift; + my $data = shift; my $paths = shift; my ( @created ); @@ -170,38 +189,51 @@ sub _mkpath { } next if -d $path; my $parent = File::Basename::dirname($path); + # Coverage note: It's not clear how we would test the condition: + # '-d $parent or $path eq $parent' unless ( -d $parent or $path eq $parent ) { - push( @created, _mkpath( $arg, [$parent] ) ); + push( @created, _mkpath( $data, [$parent] ) ); } - print "mkdir $path\n" if $arg->{verbose}; - if ( mkdir( $path, $arg->{mode} ) ) { + print "mkdir $path\n" if $data->{verbose}; + if ( mkdir( $path, $data->{mode} ) ) { push( @created, $path ); - if ( exists $arg->{owner} ) { + if ( exists $data->{owner} ) { - # NB: $arg->{group} guaranteed to be set during initialisation - if ( !chown $arg->{owner}, $arg->{group}, $path ) { - _error( $arg, -"Cannot change ownership of $path to $arg->{owner}:$arg->{group}" + # NB: $data->{group} guaranteed to be set during initialisation + if ( !chown $data->{owner}, $data->{group}, $path ) { + _error( $data, + "Cannot change ownership of $path to $data->{owner}:$data->{group}" ); } } - if ( exists $arg->{chmod} ) { - if ( !chmod $arg->{chmod}, $path ) { - _error( $arg, - "Cannot change permissions of $path to $arg->{chmod}" ); + if ( exists $data->{chmod} ) { + # Coverage note: It's not clear how we would trigger the next + # 'if' block. Failure of 'chmod' might first result in a + # system error: "Permission denied". + if ( !chmod $data->{chmod}, $path ) { + _error( $data, + "Cannot change permissions of $path to $data->{chmod}" ); } } } else { my $save_bang = $!; + + # From 'perldoc perlvar': $EXTENDED_OS_ERROR ($^E) is documented + # as: + # Error information specific to the current operating system. At the + # moment, this differs from "$!" under only VMS, OS/2, and Win32 + # (and for MacPerl). On all other platforms, $^E is always just the + # same as $!. + my ( $e, $e1 ) = ( $save_bang, $^E ); $e .= "; $e1" if $e ne $e1; # allow for another process to have created it meanwhile if ( ! -d $path ) { $! = $save_bang; - if ( $arg->{error} ) { - push @{ ${ $arg->{error} } }, { $path => $e }; + if ( $data->{error} ) { + push @{ ${ $data->{error} } }, { $path => $e }; } else { _croak("mkdir $path: $e"); @@ -238,14 +270,13 @@ sub _is_subdir { sub rmtree { my $old_style = !( @_ and __is_arg( $_[-1] ) ); - my $arg; - my $paths; + my ($arg, $data, $paths); if ($old_style) { my ( $verbose, $safe ); ( $paths, $verbose, $safe ) = @_; - $arg->{verbose} = $verbose; - $arg->{safe} = defined $safe ? $safe : 0; + $data->{verbose} = $verbose; + $data->{safe} = defined $safe ? $safe : 0; if ( defined($paths) and length($paths) ) { $paths = [$paths] unless UNIVERSAL::isa( $paths, 'ARRAY' ); @@ -264,38 +295,53 @@ sub rmtree { verbose | ); my @bad_args = (); - $arg = pop @_; + my $arg = pop @_; for my $k (sort keys %{$arg}) { - push @bad_args, $k unless $args_permitted{$k}; + if (! $args_permitted{$k}) { + push @bad_args, $k; + } + else { + $data->{$k} = $arg->{$k}; + } } _carp("Unrecognized option(s) passed to remove_tree(): @bad_args") if @bad_args; - ${ $arg->{error} } = [] if exists $arg->{error}; - ${ $arg->{result} } = [] if exists $arg->{result}; + ${ $data->{error} } = [] if exists $data->{error}; + ${ $data->{result} } = [] if exists $data->{result}; + + # Wouldn't it make sense to do some validation on @_ before assigning + # to $paths here? + # In the $old_style case we guarantee that each path is both defined + # and non-empty. We don't check that here, which means we have to + # check it later in the first condition in this line: + # if ( $ortho_root_length && _is_subdir( $ortho_root, $ortho_cwd ) ) { + # Granted, that would be a change in behavior for the two + # non-old-style interfaces. + $paths = [@_]; } - $arg->{prefix} = ''; - $arg->{depth} = 0; + $data->{prefix} = ''; + $data->{depth} = 0; my @clean_path; - $arg->{cwd} = getcwd() or do { - _error( $arg, "cannot fetch initial working directory" ); + $data->{cwd} = getcwd() or do { + _error( $data, "cannot fetch initial working directory" ); return 0; }; - for ( $arg->{cwd} ) { /\A(.*)\Z/s; $_ = $1 } # untaint + for ( $data->{cwd} ) { /\A(.*)\Z/s; $_ = $1 } # untaint for my $p (@$paths) { # need to fixup case and map \ to / on Windows my $ortho_root = _IS_MSWIN32 ? _slash_lc($p) : $p; my $ortho_cwd = - _IS_MSWIN32 ? _slash_lc( $arg->{cwd} ) : $arg->{cwd}; + _IS_MSWIN32 ? _slash_lc( $data->{cwd} ) : $data->{cwd}; my $ortho_root_length = length($ortho_root); $ortho_root_length-- if _IS_VMS; # don't compare '.' with ']' if ( $ortho_root_length && _is_subdir( $ortho_root, $ortho_cwd ) ) { local $! = 0; - _error( $arg, "cannot remove path when cwd is $arg->{cwd}", $p ); + _error( $data, "cannot remove path when cwd is $data->{cwd}", $p ); next; } @@ -312,16 +358,16 @@ sub rmtree { push @clean_path, $p; } - @{$arg}{qw(device inode perm)} = ( lstat $arg->{cwd} )[ 0, 1 ] or do { - _error( $arg, "cannot stat initial working directory", $arg->{cwd} ); + @{$data}{qw(device inode)} = ( lstat $data->{cwd} )[ 0, 1 ] or do { + _error( $data, "cannot stat initial working directory", $data->{cwd} ); return 0; }; - return _rmtree( $arg, \@clean_path ); + return _rmtree( $data, \@clean_path ); } sub _rmtree { - my $arg = shift; + my $data = shift; my $paths = shift; my $count = 0; @@ -339,8 +385,8 @@ sub _rmtree { # opposed to being truly canonical, anchored from the root (/). my $canon = - $arg->{prefix} - ? File::Spec->catfile( $arg->{prefix}, $root ) + $data->{prefix} + ? File::Spec->catfile( $data->{prefix}, $root ) : $root; my ( $ldev, $lino, $perm ) = ( lstat $root )[ 0, 1, 2 ] @@ -354,29 +400,40 @@ sub _rmtree { # see if we can escalate privileges to get in # (e.g. funny protection mask such as -w- instead of rwx) - $perm &= oct '7777'; - my $nperm = $perm | oct '700'; - if ( - !( - $arg->{safe} - or $nperm == $perm - or chmod( $nperm, $root ) - ) - ) - { - _error( $arg, - "cannot make child directory read-write-exec", $canon ); - next ROOT_DIR; + # This uses fchmod to avoid traversing outside of the proper + # location (CVE-2017-6512) + my $root_fh; + if (open($root_fh, '<', $root)) { + my ($fh_dev, $fh_inode) = (stat $root_fh )[0,1]; + $perm &= oct '7777'; + my $nperm = $perm | oct '700'; + local $@; + if ( + !( + $data->{safe} + or $nperm == $perm + or !-d _ + or $fh_dev ne $ldev + or $fh_inode ne $lino + or eval { chmod( $nperm, $root_fh ) } + ) + ) + { + _error( $data, + "cannot make child directory read-write-exec", $canon ); + next ROOT_DIR; + } + close $root_fh; } - elsif ( !chdir($root) ) { - _error( $arg, "cannot chdir to child", $canon ); + if ( !chdir($root) ) { + _error( $data, "cannot chdir to child", $canon ); next ROOT_DIR; } } my ( $cur_dev, $cur_inode, $perm ) = ( stat $curdir )[ 0, 1, 2 ] or do { - _error( $arg, "cannot stat current working directory", $canon ); + _error( $data, "cannot stat current working directory", $canon ); next ROOT_DIR; }; @@ -397,20 +454,20 @@ sub _rmtree { if ( !( - $arg->{safe} + $data->{safe} or $nperm == $perm or chmod( $nperm, $curdir ) ) ) { - _error( $arg, "cannot make directory read+writeable", $canon ); + _error( $data, "cannot make directory read+writeable", $canon ); $nperm = $perm; } my $d; $d = gensym() if $] < 5.006; if ( !opendir $d, $curdir ) { - _error( $arg, "cannot opendir", $canon ); + _error( $data, "cannot opendir", $canon ); @files = (); } else { @@ -437,9 +494,9 @@ sub _rmtree { if (@files) { # remove the contained files before the directory itself - my $narg = {%$arg}; + my $narg = {%$data}; @{$narg}{qw(device inode cwd prefix depth)} = - ( $cur_dev, $cur_inode, $updir, $canon, $arg->{depth} + 1 ); + ( $cur_dev, $cur_inode, $updir, $canon, $data->{depth} + 1 ); $count += _rmtree( $narg, \@files ); } @@ -447,49 +504,49 @@ sub _rmtree { # below fails), while we are still in the directory and may do so # without a race via '.' if ( $nperm != $perm and not chmod( $perm, $curdir ) ) { - _error( $arg, "cannot reset chmod", $canon ); + _error( $data, "cannot reset chmod", $canon ); } # don't leave the client code in an unexpected directory - chdir( $arg->{cwd} ) + chdir( $data->{cwd} ) or - _croak("cannot chdir to $arg->{cwd} from $canon: $!, aborting."); + _croak("cannot chdir to $data->{cwd} from $canon: $!, aborting."); # ensure that a chdir upwards didn't take us somewhere other # than we expected (see CVE-2002-0435) ( $cur_dev, $cur_inode ) = ( stat $curdir )[ 0, 1 ] or _croak( - "cannot stat prior working directory $arg->{cwd}: $!, aborting." + "cannot stat prior working directory $data->{cwd}: $!, aborting." ); if (_NEED_STAT_CHECK) { - ( $arg->{device} eq $cur_dev and $arg->{inode} eq $cur_inode ) - or _croak( "previous directory $arg->{cwd} " + ( $data->{device} eq $cur_dev and $data->{inode} eq $cur_inode ) + or _croak( "previous directory $data->{cwd} " . "changed before entering $canon, " . "expected dev=$ldev ino=$lino, " . "actual dev=$cur_dev ino=$cur_inode, aborting." ); } - if ( $arg->{depth} or !$arg->{keep_root} ) { - if ( $arg->{safe} + if ( $data->{depth} or !$data->{keep_root} ) { + if ( $data->{safe} && ( _IS_VMS ? !&VMS::Filespec::candelete($root) : !-w $root ) ) { - print "skipped $root\n" if $arg->{verbose}; + print "skipped $root\n" if $data->{verbose}; next ROOT_DIR; } if ( _FORCE_WRITABLE and !chmod $perm | oct '700', $root ) { - _error( $arg, "cannot make directory writeable", $canon ); + _error( $data, "cannot make directory writeable", $canon ); } - print "rmdir $root\n" if $arg->{verbose}; + print "rmdir $root\n" if $data->{verbose}; if ( rmdir $root ) { - push @{ ${ $arg->{result} } }, $root if $arg->{result}; + push @{ ${ $data->{result} } }, $root if $data->{result}; ++$count; } else { - _error( $arg, "cannot remove directory", $canon ); + _error( $data, "cannot remove directory", $canon ); if ( _FORCE_WRITABLE && !chmod( $perm, @@ -498,7 +555,7 @@ sub _rmtree { ) { _error( - $arg, + $data, sprintf( "cannot restore permissions to 0%o", $perm ), $canon @@ -515,7 +572,7 @@ sub _rmtree { && ( $root !~ m/(?<!\^)[\]>]+/ ); # not already in VMS syntax if ( - $arg->{safe} + $data->{safe} && ( _IS_VMS ? !&VMS::Filespec::candelete($root) @@ -523,7 +580,7 @@ sub _rmtree { ) ) { - print "skipped $root\n" if $arg->{verbose}; + print "skipped $root\n" if $data->{verbose}; next ROOT_DIR; } @@ -532,19 +589,19 @@ sub _rmtree { and $nperm != $perm and not chmod $nperm, $root ) { - _error( $arg, "cannot make file writeable", $canon ); + _error( $data, "cannot make file writeable", $canon ); } - print "unlink $canon\n" if $arg->{verbose}; + print "unlink $canon\n" if $data->{verbose}; # delete all versions under VMS for ( ; ; ) { if ( unlink $root ) { - push @{ ${ $arg->{result} } }, $root if $arg->{result}; + push @{ ${ $data->{result} } }, $root if $data->{result}; } else { - _error( $arg, "cannot unlink file", $canon ); + _error( $data, "cannot unlink file", $canon ); _FORCE_WRITABLE and chmod( $perm, $root ) - or _error( $arg, + or _error( $data, sprintf( "cannot restore permissions to 0%o", $perm ), $canon ); last; @@ -576,41 +633,41 @@ File::Path - Create or remove directory trees =head1 VERSION -This document describes version 2.12 of File::Path. +2.13 - released May 31 2017. =head1 SYNOPSIS - use File::Path qw(make_path remove_tree); - - @created = make_path('foo/bar/baz', '/zug/zwang'); - @created = make_path('foo/bar/baz', '/zug/zwang', { - verbose => 1, - mode => 0711, - }); - make_path('foo/bar/baz', '/zug/zwang', { - chmod => 0777, - }); - - $removed_count = remove_tree('foo/bar/baz', '/zug/zwang'); - $removed_count = remove_tree('foo/bar/baz', '/zug/zwang', { - verbose => 1, - error => \my $err_list, - }); - - # legacy (interface promoted before v2.00) - @created = mkpath('/foo/bar/baz'); - @created = mkpath('/foo/bar/baz', 1, 0711); - @created = mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711); - $removed_count = rmtree('foo/bar/baz', 1, 1); - $removed_count = rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1); - - # legacy (interface promoted before v2.06) - @created = mkpath('foo/bar/baz', '/zug/zwang', { verbose => 1, mode => 0711 }); - $removed_count = rmtree('foo/bar/baz', '/zug/zwang', { verbose => 1, mode => 0711 }); + use File::Path qw(make_path remove_tree); + + @created = make_path('foo/bar/baz', '/zug/zwang'); + @created = make_path('foo/bar/baz', '/zug/zwang', { + verbose => 1, + mode => 0711, + }); + make_path('foo/bar/baz', '/zug/zwang', { + chmod => 0777, + }); + + $removed_count = remove_tree('foo/bar/baz', '/zug/zwang', { + verbose => 1, + error => \my $err_list, + safe => 1, + }); + + # legacy (interface promoted before v2.00) + @created = mkpath('/foo/bar/baz'); + @created = mkpath('/foo/bar/baz', 1, 0711); + @created = mkpath(['/foo/bar/baz', 'blurfl/quux'], 1, 0711); + $removed_count = rmtree('foo/bar/baz', 1, 1); + $removed_count = rmtree(['foo/bar/baz', 'blurfl/quux'], 1, 1); + + # legacy (interface promoted before v2.06) + @created = mkpath('foo/bar/baz', '/zug/zwang', { verbose => 1, mode => 0711 }); + $removed_count = rmtree('foo/bar/baz', '/zug/zwang', { verbose => 1, mode => 0711 }); =head1 DESCRIPTION -This module provide a convenient way to create directories of +This module provides a convenient way to create directories of arbitrary depth and to delete an entire directory subtree from the filesystem. @@ -623,7 +680,7 @@ The following functions are provided: =item make_path( $dir1, $dir2, ...., \%opts ) The C<make_path> function creates the given directories if they don't -exists before, much like the Unix command C<mkdir -p>. +exist before, much like the Unix command C<mkdir -p>. The function accepts a list of directories to be created. Its behaviour may be tuned by an optional hashref appearing as the last @@ -639,7 +696,7 @@ The following keys are recognised in the option hash: =item mode => $num The numeric permissions mode to apply to each created directory -(defaults to 0777), to be modified by the current C<umask>. If the +(defaults to C<0777>), to be modified by the current C<umask>. If the directory already exists (and thus does not need to be created), the permissions will not be modified. @@ -675,9 +732,9 @@ in an C<eval> block. =item uid => $owner If present, will cause any created directory to be owned by C<$owner>. -If the value is numeric, it will be interpreted as a uid, otherwise -as username is assumed. An error will be issued if the username cannot be -mapped to a uid, or the uid does not exist, or the process lacks the +If the value is numeric, it will be interpreted as a uid; otherwise a +username is assumed. An error will be issued if the username cannot be +mapped to a uid, the uid does not exist or the process lacks the privileges to change ownership. Ownership of directories that already exist will not be changed. @@ -686,11 +743,11 @@ C<user> and C<uid> are aliases of C<owner>. =item group => $group -If present, will cause any created directory to be owned by the group C<$group>. -If the value is numeric, it will be interpreted as a gid, otherwise -as group name is assumed. An error will be issued if the group name cannot be -mapped to a gid, or the gid does not exist, or the process lacks the -privileges to change group ownership. +If present, will cause any created directory to be owned by the group +C<$group>. If the value is numeric, it will be interpreted as a gid; +otherwise a group name is assumed. An error will be issued if the +group name cannot be mapped to a gid, the gid does not exist or the +process lacks the privileges to change group ownership. Group ownership of directories that already exist will not be changed. @@ -706,9 +763,10 @@ Group ownership of directories that already exist will not be changed. =item mkpath( $dir1, $dir2,..., \%opt ) -The mkpath() function provide the legacy interface of make_path() with -a different interpretation of the arguments passed. The behaviour and -return value of the function is otherwise identical to make_path(). +The C<mkpath()> function provide the legacy interface of +C<make_path()> with a different interpretation of the arguments +passed. The behaviour and return value of the function is otherwise +identical to C<make_path()>. =item remove_tree( $dir1, $dir2, .... ) @@ -716,16 +774,27 @@ return value of the function is otherwise identical to make_path(). The C<remove_tree> function deletes the given directories and any files and subdirectories they might contain, much like the Unix -command C<rm -r> or the Windows commands C<rmdir /s> and C<rd /s>. The -only exception to the function similarity is C<remove_tree> accepts -only directories whereas C<rm -r> also accepts files. +command C<rm -rf> or the Windows commands C<rmdir /s> and C<rd /s>. The +only exception to the function similarity is that C<remove_tree> accepts +only directories whereas C<rm -rf> also accepts files. The function accepts a list of directories to be removed. Its behaviour may be tuned by an optional hashref appearing as the last parameter on the call. If an empty string is passed to C<remove_tree>, an error will occur. -The functions returns the number of files successfully deleted. +B<NOTE:> For security reasons, we strongly advise use of the +hashref-as-final-argument syntax -- specifically, with a setting of the C<safe> +element to a true value. + + remove_tree( $dir1, $dir2, ...., + { + safe => 1, + ... # other key-value pairs + }, + ); + +The function returns the number of files successfully deleted. The following keys are recognised in the option hash: @@ -751,7 +820,7 @@ When set to a true value, will cause all files and subdirectories to be removed, except the initially specified directories. This comes in handy when cleaning out an application's scratch directory. - remove_tree( '/tmp', {keep_root => 1} ); + remove_tree( '/tmp', {keep_root => 1} ); =item result => \$res @@ -760,8 +829,8 @@ This scalar will be made to reference an array, which will be used to store all files and directories unlinked during the call. If nothing is unlinked, the array will be empty. - remove_tree( '/tmp', {result => \my $list} ); - print "unlinked $_\n" for @$list; + remove_tree( '/tmp', {result => \my $list} ); + print "unlinked $_\n" for @$list; This is a useful alternative to the C<verbose> key. @@ -791,10 +860,21 @@ of hand. This is the safest course of action. =item rmtree( $dir1, $dir2,..., \%opt ) -The rmtree() function provide the legacy interface of remove_tree() -with a different interpretation of the arguments passed. The behaviour -and return value of the function is otherwise identical to -remove_tree(). +The C<rmtree()> function provide the legacy interface of +C<remove_tree()> with a different interpretation of the arguments +passed. The behaviour and return value of the function is otherwise +identical to C<remove_tree()>. + +B<NOTE:> For security reasons, we strongly advise use of the +hashref-as-final-argument syntax, specifically with a setting of the C<safe> +element to a true value. + + rmtree( $dir1, $dir2, ...., + { + safe => 1, + ... # other key-value pairs + }, + ); =back @@ -813,9 +893,9 @@ C<make_path> or C<remove_tree>, you should take additional precautions. =back -If C<make_path> or C<remove_tree> encounter an error, a diagnostic +If C<make_path> or C<remove_tree> encounters an error, a diagnostic message will be printed to C<STDERR> via C<carp> (for non-fatal -errors), or via C<croak> (for fatal errors). +errors) or via C<croak> (for fatal errors). If this behaviour is not desirable, the C<error> attribute may be used to hold a reference to a variable, which will be used to store @@ -828,7 +908,7 @@ encountered the diagnostic key will be empty. An example usage looks like: remove_tree( 'foo/bar', 'bar/rat', {error => \my $err} ); - if (@$err) { + if ($err && @$err) { for my $diag (@$err) { my ($file, $message) = %$diag; if ($file eq '') { @@ -882,16 +962,16 @@ to at least 2.08 in order to avoid surprises. =head3 SECURITY CONSIDERATIONS -There were race conditions 1.x implementations of File::Path's +There were race conditions in the 1.x implementations of File::Path's C<rmtree> function (although sometimes patched depending on the OS distribution or platform). The 2.0 version contains code to avoid the problem mentioned in CVE-2002-0435. See the following pages for more information: - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=286905 - http://www.nntp.perl.org/group/perl.perl5.porters/2005/01/msg97623.html - http://www.debian.org/security/2005/dsa-696 + http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=286905 + http://www.nntp.perl.org/group/perl.perl5.porters/2005/01/msg97623.html + http://www.debian.org/security/2005/dsa-696 Additionally, unless the C<safe> parameter is set (or the third parameter in the traditional interface is TRUE), should a @@ -899,6 +979,27 @@ C<remove_tree> be interrupted, files that were originally in read-only mode may now have their permissions set to a read-write (or "delete OK") mode. +The following CVE reports were previously filed against File-Path and are +believed to have been addressed: + +=over 4 + +=item * L<http://cve.circl.lu/cve/CVE-2004-0452> + +=item * L<http://cve.circl.lu/cve/CVE-2005-0448> + +=back + +In February 2017 the cPanel Security Team reported an additional vulnerability +in File-Path. The C<chmod()> logic to make directories traversable can be +abused to set the mode on an attacker-chosen file to an attacker-chosen value. +This is due to the time-of-check-to-time-of-use (TOCTTOU) race condition +(L<https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use>) between the +C<stat()> that decides the inode is a directory and the C<chmod()> that tries +to make it user-rwx. CPAN versions 2.13 and later incorporate a patch +provided by John Lightsey to address this problem. This vulnerability has +been reported as CVE-2017-6512. + =head1 DIAGNOSTICS FATAL errors will cause the program to halt (C<croak>), since the @@ -907,7 +1008,7 @@ can always be trapped with C<eval>, but it's not a good idea. Under the circumstances, dying is the best thing to do). SEVERE errors may be trapped using the modern interface. If the -they are not trapped, or the old interface is used, such an error +they are not trapped, or if the old interface is used, such an error will cause the program will halt. All other errors may be trapped using the modern interface, otherwise @@ -918,7 +1019,7 @@ they will be C<carp>ed about. Program execution will not be halted. =item mkdir [path]: [errmsg] (SEVERE) C<make_path> was unable to create the path. Probably some sort of -permissions error at the point of departure, or insufficient resources +permissions error at the point of departure or insufficient resources (such as free inodes on Unix). =item No root path(s) specified @@ -997,7 +1098,7 @@ halts to avoid a race condition from occurring. =item cannot stat prior working directory [dir]: [errmsg], aborting. (FATAL) -C<remove_tree> was unable to stat the parent directory after have returned +C<remove_tree> was unable to stat the parent directory after having returned from the child. Since there is no way of knowing if we returned to where we think we should be (by comparing device and inode) the only way out is to C<croak>. @@ -1017,9 +1118,9 @@ execution continues, but the directory may possibly not be deleted. =item cannot remove directory [dir]: [errmsg] -C<remove_tree> attempted to remove a directory, but failed. This may because +C<remove_tree> attempted to remove a directory, but failed. This may be because some objects that were unable to be removed remain in the directory, or -a permissions issue. The directory will be left behind. +it could be a permissions issue. The directory will be left behind. =item cannot restore permissions of [dir] to [0nnn]: [errmsg] @@ -1087,14 +1188,16 @@ to examining directory trees. The following describes F<File::Path> limitations and how to report bugs. -=head2 MULTITHREAD APPLICATIONS +=head2 MULTITHREADED APPLICATIONS -F<File::Path> B<rmtree> and B<remove_tree> will not work with multithreaded -applications due to its use of B<chdir>. At this time, no warning or error -results and you will certainly encounter unexpected results. +F<File::Path> C<rmtree> and C<remove_tree> will not work with +multithreaded applications due to its use of C<chdir>. At this time, +no warning or error is generated in this situation. You will +certainly encounter unexpected results. -The implementation that surfaces this limitation may change in a future -release. +The implementation that surfaces this limitation will not be changed. See the +F<File::Path::Tiny> module for functionality similar to F<File::Path> but which does +not C<chdir>. =head2 NFS Mount Points @@ -1147,8 +1250,14 @@ Contributors to File::Path, in alphabetical order. =item <F<bulkdd@cpan.org>> +=item Charlie Gonzalez <F<itcharlie@cpan.org>> + =item Craig A. Berry <F<craigberry@mac.com>> +=item James E Keenan <F<jkeenan@cpan.org>> + +=item John Lightsey <F<john@perlsec.org>> + =item Richard Elberger <F<riche@cpan.org>> =item Ryan Yee <F<ryee@cpan.org>> @@ -1157,12 +1266,14 @@ Contributors to File::Path, in alphabetical order. =item Tom Lutz <F<tommylutz@gmail.com>> +=item Will Sheppard <F<willsheppard@github>> + =back =head1 COPYRIGHT This module is copyright (C) Charles Bailey, Tim Bunce, David Landgren, -James Keenan, and Richard Elberger 1995-2015. All rights reserved. +James Keenan and Richard Elberger 1995-2017. All rights reserved. =head1 LICENSE diff --git a/gnu/usr.bin/perl/cpan/File-Path/t/FilePathTest.pm b/gnu/usr.bin/perl/cpan/File-Path/t/FilePathTest.pm index f9e82893119..88b411d4bb3 100644 --- a/gnu/usr.bin/perl/cpan/File-Path/t/FilePathTest.pm +++ b/gnu/usr.bin/perl/cpan/File-Path/t/FilePathTest.pm @@ -3,18 +3,26 @@ use strict; use warnings; use base 'Exporter'; use SelectSaver; +use Carp; use Cwd; use File::Spec::Functions; +use File::Path (); +use Test::More (); -our @EXPORT = qw(_run_for_warning _run_for_verbose _basedir - _cannot_delete_safe_mode - _verbose_expected); +our @EXPORT_OK = qw( + _run_for_warning + _run_for_verbose + _cannot_delete_safe_mode + _verbose_expected + create_3_level_subdirs + cleanup_3_level_subdirs +); sub _basedir { - return catdir( curdir(), - sprintf( 'test-%x-%x-%x', time, $$, rand(99999) ), + return catdir( + curdir(), + sprintf( 'test-%x-%x-%x', time, $$, rand(99999) ), ); - } sub _run_for_warning { @@ -109,4 +117,28 @@ END } } +sub create_3_level_subdirs { + my @dirnames = @_; + my %seen = map {$_ => 1} @dirnames; + croak "Need 3 distinct names for subdirectories" + unless scalar(keys %seen) == 3; + my $tdir = File::Spec::Functions::tmpdir(); + my $least_deep = catdir($tdir, $dirnames[0]); + my $next_deepest = catdir($least_deep, $dirnames[1]); + my $deepest = catdir($next_deepest, $dirnames[2]); + return ($least_deep, $next_deepest, $deepest); +} + +sub cleanup_3_level_subdirs { + # runs 2 tests + my $least_deep = shift; + croak "Must provide path of least subdirectory" + unless (length($least_deep) and (-d $least_deep)); + my $x; + my $opts = { error => \$x }; + File::Path::remove_tree($least_deep, $opts); + Test::More::ok(! -d $least_deep, "directory '$least_deep' removed, as expected"); + Test::More::is(scalar(@{$x}), 0, "no error messages using remove_tree() with \$opts"); +} + 1; diff --git a/gnu/usr.bin/perl/cpan/File-Path/t/Path-Class.t b/gnu/usr.bin/perl/cpan/File-Path/t/Path-Class.t new file mode 100644 index 00000000000..d896fbbf553 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/File-Path/t/Path-Class.t @@ -0,0 +1,50 @@ +use strict; +use warnings; +use Test::More tests => 32; + +eval "require Path::Class"; + + +SKIP: { + skip "Path::Class required to run this test", 32 if $@; + use File::Path qw(remove_tree make_path); + Path::Class->import; + + my $name = 'test'; + my $dir = dir($name); + + for my $mk_dir ($name, dir($name)) { + for my $mk_pass_arg (0, 1) { + + for my $rm_dir ($name, dir($name)) { + for my $rm_pass_arg (0, 1) { + remove_tree($name) if -e $name; + + my ($mk_args, $mk_desc) = test($mk_dir, $mk_pass_arg); + make_path(@$mk_args); + + if (ok( -d $dir, "we made $dir ($mk_desc)")) { + my ($rm_args, $rm_desc) = test($rm_dir, $rm_pass_arg); + remove_tree(@$rm_args); + ok( ! -d $dir, "...then we removed $dir ($rm_desc)"); + } else { + fail("...can't remove it if we didn't create it"); + } + } + } + } + } +} + +sub test { + my ($dir, $pass_arg) = @_; + + my $args = [ $dir, ($pass_arg ? {} : ()) ]; + my $desc = sprintf( + 'dir isa %s, second arg is %s', + (ref($dir) || 'string'), + ($pass_arg ? '{}' : 'not passed') + ); + + return ($args, $desc); +} diff --git a/gnu/usr.bin/perl/cpan/File-Path/t/Path.t b/gnu/usr.bin/perl/cpan/File-Path/t/Path.t index 5644f57a516..9be39a5de2f 100755 --- a/gnu/usr.bin/perl/cpan/File-Path/t/Path.t +++ b/gnu/usr.bin/perl/cpan/File-Path/t/Path.t @@ -3,11 +3,20 @@ use strict; -use Test::More tests => 127; +use Test::More tests => 167; use Config; use Fcntl ':mode'; -use lib 't/'; -use FilePathTest; +use lib './t'; +use FilePathTest qw( + _run_for_warning + _run_for_verbose + _cannot_delete_safe_mode + _verbose_expected + create_3_level_subdirs + cleanup_3_level_subdirs +); +use Errno qw(:POSIX); +use Carp; BEGIN { use_ok('Cwd'); @@ -17,6 +26,13 @@ BEGIN { my $Is_VMS = $^O eq 'VMS'; +my $fchmod_supported = 0; +if (open my $fh, curdir()) { + my ($perm) = (stat($fh))[2]; + $perm &= 07777; + eval { $fchmod_supported = chmod( $perm, $fh); }; +} + # first check for stupid permissions second for full, so we clean up # behind ourselves for my $perm (0111,0777) { @@ -298,16 +314,19 @@ is($created[0], $dir, "created directory (old style 3 mode undef) cross-check"); is(rmtree($dir, 0, undef), 1, "removed directory 3 verbose undef"); -$dir = catdir($tmp_base,'G'); -$dir = VMS::Filespec::unixify($dir) if $Is_VMS; +SKIP: { + skip "fchmod of directories not supported on this platform", 3 unless $fchmod_supported; + $dir = catdir($tmp_base,'G'); + $dir = VMS::Filespec::unixify($dir) if $Is_VMS; -@created = mkpath($dir, undef, 0200); + @created = mkpath($dir, undef, 0400); -is(scalar(@created), 1, "created write-only dir"); + is(scalar(@created), 1, "created read-only dir"); -is($created[0], $dir, "created write-only directory cross-check"); + is($created[0], $dir, "created read-only directory cross-check"); -is(rmtree($dir), 1, "removed write-only dir"); + is(rmtree($dir), 1, "removed read-only dir"); +} # borderline new-style heuristics if (chdir $tmp_base) { @@ -449,26 +468,28 @@ SKIP: { } SKIP : { - my $skip_count = 19; + my $skip_count = 18; # this test will fail on Windows, as per: # http://perldoc.perl.org/perlport.html#chmod skip "Windows chmod test skipped", $skip_count if $^O eq 'MSWin32'; + skip "fchmod() on directories is not supported on this platform", $skip_count + unless $fchmod_supported; my $mode; my $octal_mode; my @inputs = ( - 0777, 0700, 0070, 0007, - 0333, 0300, 0030, 0003, - 0111, 0100, 0010, 0001, - 0731, 0713, 0317, 0371, 0173, 0137, - 00 ); + 0777, 0700, 0470, 0407, + 0433, 0400, 0430, 0403, + 0111, 0100, 0110, 0101, + 0731, 0713, 0317, 0371, + 0173, 0137); my $input; my $octal_input; - $dir = catdir($tmp_base, 'chmod_test'); foreach (@inputs) { $input = $_; + $dir = catdir($tmp_base, sprintf("chmod_test%04o", $input)); # We can skip from here because 0 is last in the list. skip "Mode of 0 means assume user defaults on VMS", 1 if ($input == 0 && $Is_VMS); @@ -476,7 +497,11 @@ SKIP : { $mode = (stat($dir))[2]; $octal_mode = S_IMODE($mode); $octal_input = sprintf "%04o", S_IMODE($input); - is($octal_mode,$input, "create a new directory with chmod $input ($octal_input)"); + SKIP: { + skip "permissions are not fully supported by the filesystem", 1 + if (($^O eq 'MSWin32' || $^O eq 'cygwin') && ((Win32::FsType())[1] & 8) == 0); + is($octal_mode,$input, "create a new directory with chmod $input ($octal_input)"); + } rmtree( $dir ); } } @@ -587,29 +612,27 @@ SKIP: { my $dir2 = catdir( $base, 'B'); { - my $warn; - $SIG{__WARN__} = sub { $warn = shift }; - - my @created = make_path( - $dir, - $dir2, - { mode => 0711, foo => 1, bar => 1 } - ); + my $warn = _run_for_warning( sub { + my @created = make_path( + $dir, + $dir2, + { mode => 0711, foo => 1, bar => 1 } + ); + } ); like($warn, - qr/Unrecognized option\(s\) passed to make_path\(\):.*?bar.*?foo/, + qr/Unrecognized option\(s\) passed to mkpath\(\) or make_path\(\):.*?bar.*?foo/, 'make_path with final hashref warned due to unrecognized options' ); } { - my $warn; - $SIG{__WARN__} = sub { $warn = shift }; - - my @created = remove_tree( - $dir, - $dir2, - { foo => 1, bar => 1 } - ); + my $warn = _run_for_warning( sub { + my @created = remove_tree( + $dir, + $dir2, + { foo => 1, bar => 1 } + ); + } ); like($warn, qr/Unrecognized option\(s\) passed to remove_tree\(\):.*?bar.*?foo/, 'remove_tree with final hashref failed due to unrecognized options' @@ -656,7 +679,7 @@ is( { my ($x, $message, $object, $expect, $rv, $arg, $error); my ($k, $v, $second_error, $third_error); - local $! = 2; + local $! = ENOENT; $x = $!; $message = 'message in a bottle'; @@ -729,3 +752,186 @@ is( is($k, '', "key of hash is empty string, since 3rd arg was undef"); is($v, $expect, "value of hash is 2nd arg: $message"); } + +{ + # https://rt.cpan.org/Ticket/Display.html?id=117019 + # remove_tree(): Permit re-use of options hash without issuing a warning + + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| a b c | ); + my @created; + @created = File::Path::make_path($deepest, { mode => 0711 }); + is(scalar(@created), 3, "Created 3 subdirectories"); + + my $x = ''; + my $opts = { error => \$x }; + File::Path::remove_tree($deepest, $opts); + ok(! -d $deepest, "directory '$deepest' removed, as expected"); + + my $warn; + $warn = _run_for_warning( sub { File::Path::remove_tree($next_deepest, $opts); } ); + ok(! $warn, "CPAN 117019: No warning thrown when re-using \$opts"); + ok(! -d $next_deepest, "directory '$next_deepest' removed, as expected"); + + $warn = _run_for_warning( sub { File::Path::remove_tree($least_deep, $opts); } ); + ok(! $warn, "CPAN 117019: No warning thrown when re-using \$opts"); + ok(! -d $least_deep, "directory '$least_deep' removed, as expected"); +} + +{ + # Corner cases with respect to arguments provided to functions + my $count; + + $count = remove_tree(); + is($count, 0, + "If not provided with any paths, remove_tree() will return a count of 0 things deleted"); + + $count = remove_tree(''); + is($count, 0, + "If not provided with any paths, remove_tree() will return a count of 0 things deleted"); + + my $warn; + $warn = _run_for_warning( sub { $count = rmtree(); } ); + like($warn, qr/No root path\(s\) specified/s, "Got expected carp"); + is($count, 0, + "If not provided with any paths, remove_tree() will return a count of 0 things deleted"); + + $warn = _run_for_warning( sub {$count = rmtree(undef); } ); + like($warn, qr/No root path\(s\) specified/s, "Got expected carp"); + is($count, 0, + "If provided only with an undefined value, remove_tree() will return a count of 0 things deleted"); + + $warn = _run_for_warning( sub {$count = rmtree(''); } ); + like($warn, qr/No root path\(s\) specified/s, "Got expected carp"); + is($count, 0, + "If provided with an empty string for a path, remove_tree() will return a count of 0 things deleted"); + + $count = make_path(); + is($count, 0, + "If not provided with any paths, make_path() will return a count of 0 things created"); + + $count = mkpath(); + is($count, 0, + "If not provided with any paths, make_path() will return a count of 0 things created"); +} + +SKIP: { + my $skip_count = 5; + skip "Windows will not set this error condition", $skip_count + if $^O eq 'MSWin32'; + + # mkpath() with hashref: case of phony user + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| d e f | ); + my (@created, $error); + my $user = join('_' => 'foobar', $$); + @created = mkpath($deepest, { mode => 0711, user => $user, error => \$error }); + TODO: { + local $TODO = "Notwithstanding the phony 'user', mkpath will actually create subdirectories; should it?"; + is(scalar(@created), 0, "No subdirectories created"); + } + is(scalar(@$error), 1, "caught error condition" ); + my ($file, $message) = each %{$error->[0]}; + like($message, + qr/unable to map $user to a uid, ownership not changed/s, + "Got expected error message for phony user", + ); + + cleanup_3_level_subdirs($least_deep); +} + +{ + # mkpath() with hashref: case of valid uid + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| j k l | ); + my (@created, $error); + @created = mkpath($deepest, { mode => 0711, uid => $>, error => \$error }); + is(scalar(@created), 3, "Provide valid 'uid' argument: 3 subdirectories created"); + + cleanup_3_level_subdirs($least_deep); +} + +SKIP: { + my $skip_count = 3; + skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count + if $^O eq 'MSWin32'; + + # mkpath() with hashref: case of valid owner + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| m n o | ); + my (@created, $error); + my $name = getpwuid($>); + @created = mkpath($deepest, { mode => 0711, owner => $name, error => \$error }); + is(scalar(@created), 3, "Provide valid 'owner' argument: 3 subdirectories created"); + + cleanup_3_level_subdirs($least_deep); +} + +SKIP: { + my $skip_count = 5; + skip "Windows will not set this error condition", $skip_count + if $^O eq 'MSWin32'; + + # mkpath() with hashref: case of phony group + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| p q r | ); + my (@created, $error); + my $bad_group = join('_' => 'foobarbaz', $$); + @created = mkpath($deepest, { mode => 0711, group => $bad_group, error => \$error }); + TODO: { + local $TODO = "Notwithstanding the phony 'group', mkpath will actually create subdirectories; should it?"; + is(scalar(@created), 0, "No subdirectories created"); + } + is(scalar(@$error), 1, "caught error condition" ); + my ($file, $message) = each %{$error->[0]}; + like($message, + qr/unable to map $bad_group to a gid, group ownership not changed/s, + "Got expected error message for phony user", + ); + + cleanup_3_level_subdirs($least_deep); +} + +{ + # mkpath() with hashref: case of valid group + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| s t u | ); + my (@created, $error); + @created = mkpath($deepest, { mode => 0711, group => $(, error => \$error }); + is(scalar(@created), 3, "Provide valid 'group' argument: 3 subdirectories created"); + + cleanup_3_level_subdirs($least_deep); +} + +SKIP: { + my $skip_count = 3; + skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count + if $^O eq 'MSWin32'; + + # mkpath() with hashref: case of valid group + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| v w x | ); + my (@created, $error); + my $group_name = (getgrgid($())[0]; + @created = mkpath($deepest, { mode => 0711, group => $group_name, error => \$error }); + is(scalar(@created), 3, "Provide valid 'group' argument: 3 subdirectories created"); + + cleanup_3_level_subdirs($least_deep); +} + +SKIP: { + my $skip_count = 3; + skip "getpwuid() and getgrgid() not implemented on Windows", $skip_count + if $^O eq 'MSWin32'; + + # mkpath() with hashref: case of valid owner and group + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| delta epsilon zeta | ); + my (@created, $error); + my $name = getpwuid($>); + my $group_name = (getgrgid($())[0]; + @created = mkpath($deepest, { mode => 0711, owner => $name, group => $group_name, error => \$error }); + is(scalar(@created), 3, "Provide valid 'owner' and 'group' 'group' arguments: 3 subdirectories created"); + + cleanup_3_level_subdirs($least_deep); +} diff --git a/gnu/usr.bin/perl/cpan/File-Path/t/Path_root.t b/gnu/usr.bin/perl/cpan/File-Path/t/Path_root.t index 36aeb1677de..2647b7fd121 100644 --- a/gnu/usr.bin/perl/cpan/File-Path/t/Path_root.t +++ b/gnu/usr.bin/perl/cpan/File-Path/t/Path_root.t @@ -1,15 +1,17 @@ use strict; use Test::More; use Config; -use lib 't/'; -use FilePathTest; +use lib './t'; +use FilePathTest qw( + _run_for_warning +); use File::Path qw(rmtree mkpath make_path remove_tree); use File::Spec::Functions; my $prereq = prereq(); plan skip_all => $prereq if defined $prereq; -plan tests => 8; +plan tests => 11; my $pwent = max_u(); my $grent = max_g(); @@ -60,21 +62,35 @@ is(scalar(@created), 1, "created a directory owned by $max_user:$max_group..."); is($dir_uid, $max_uid, "... owned by $max_uid"); is($dir_gid, $max_gid, "... owned by group $max_gid"); -SKIP: { - skip('Skip until RT 85878 is fixed', 1); +{ # invent a user and group that don't exist do { ++$max_user } while ( getpwnam( $max_user ) ); do { ++$max_group } while ( getgrnam( $max_group ) ); $dir = catdir($dir_stem, 'aad'); - my $rv = _run_for_warning( sub { make_path( $dir, - { user => $max_user, - group => $max_group } ) } ); + my $rv = _run_for_warning( sub { + make_path( + $dir, + { user => $max_user, group => $max_group } + ) + } ); + like( $rv, + qr{unable to map $max_user to a uid, ownership not changed:}s, + "created a directory not owned by $max_user:$max_group...", + ); like( $rv, - qr{\Aunable to map $max_user to a uid, ownership not changed: .* at \S+ line \d+ -unable to map $max_group to a gid, group ownership not changed: .* at \S+ line \d+\b}, - "created a directory not owned by $max_user:$max_group..." - ); + qr{unable to map $max_group to a gid, group ownership not changed:}s, + "created a directory not owned by $max_user:$max_group...", + ); +} + +{ + # cleanup + my $x; + my $opts = { error => \$x }; + remove_tree($tmp_base, $opts); + ok(! -d $tmp_base, "directory '$tmp_base' removed, as expected"); + is(scalar(@{$x}), 0, "no error messages using remove_tree() with \$opts"); } sub max_u { diff --git a/gnu/usr.bin/perl/cpan/File-Path/t/Path_win32.t b/gnu/usr.bin/perl/cpan/File-Path/t/Path_win32.t index 47168822b96..89b0b2f045c 100644 --- a/gnu/usr.bin/perl/cpan/File-Path/t/Path_win32.t +++ b/gnu/usr.bin/perl/cpan/File-Path/t/Path_win32.t @@ -1,16 +1,20 @@ use strict; use Test::More; -use lib 't/'; -use FilePathTest; +use lib './t'; +use FilePathTest qw( + create_3_level_subdirs + cleanup_3_level_subdirs +); use File::Path; use Cwd; use File::Spec::Functions; +use Carp; plan skip_all => 'not win32' unless $^O eq 'MSWin32'; my ($ignore, $major, $minor, $build, $id) = Win32::GetOSVersion(); plan skip_all => "WinXP or later" unless $id >= 2 && ($major > 5 || $major == 5 && $minor >= 1); -plan tests => 3; +plan tests => 9; my $tmp_base = catdir( curdir(), @@ -30,3 +34,29 @@ ok(-d $UNC_path, 'mkpath on Win32 UNC path made dir'); my $removed = rmtree($UNC_path); cmp_ok($removed, '>', 0, "removed $removed entries from $UNC_path"); + +{ + my ($least_deep, $next_deepest, $deepest) = + create_3_level_subdirs( qw| d e f | ); + my (@created, $error); + my $user = join('_' => 'foobar', $$); + { + my $warn; + $SIG{__WARN__} = sub { $warn = shift }; + + @created = mkpath($deepest, { mode => 0711, user => $user, error => \$error }); + like($warn, + qr/Option\(s\) implausible on Win32 passed to mkpath\(\) or make_path\(\)/, + 'make_path with final hashref warned due to options implausible on Win32' + ); + TODO: { + local $TODO = "Notwithstanding the Win32-implausible 'user', mkpath will actually create subdirectories; should it?"; + is(scalar(@created), 0, "No subdirectories created"); + } + is(scalar(@created), 3, "3 subdirectories created"); + is(scalar(@$error), 0, "no error condition" ); + } + + cleanup_3_level_subdirs($least_deep); +} + diff --git a/gnu/usr.bin/perl/cpan/IO-Compress/private/MakeUtil.pm b/gnu/usr.bin/perl/cpan/IO-Compress/private/MakeUtil.pm index 47aebd60743..9d7e5ed262d 100644 --- a/gnu/usr.bin/perl/cpan/IO-Compress/private/MakeUtil.pm +++ b/gnu/usr.bin/perl/cpan/IO-Compress/private/MakeUtil.pm @@ -35,7 +35,8 @@ sub MY::libscan my $path = shift; return undef - if $path =~ /(~|\.bak|_bak)$/ || + if $path =~ /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/ || + $path =~ /(~|\.bak|_bak)$/ || $path =~ /\..*\.sw(o|p)$/ || $path =~ /\B\.svn\b/; diff --git a/gnu/usr.bin/perl/cpan/NEXT/lib/NEXT.pm b/gnu/usr.bin/perl/cpan/NEXT/lib/NEXT.pm index a77bb387433..72dbee8c51c 100644 --- a/gnu/usr.bin/perl/cpan/NEXT/lib/NEXT.pm +++ b/gnu/usr.bin/perl/cpan/NEXT/lib/NEXT.pm @@ -190,7 +190,7 @@ __END__ =head1 NAME -NEXT.pm - Provide a pseudo-class NEXT (et al) that allows method redispatch +NEXT - Provide a pseudo-class NEXT (et al) that allows method redispatch =head1 SYNOPSIS diff --git a/gnu/usr.bin/perl/cpan/Pod-Parser/lib/Pod/PlainText.pm b/gnu/usr.bin/perl/cpan/Pod-Parser/lib/Pod/PlainText.pm index 3db4d903cd6..03252e93c71 100644 --- a/gnu/usr.bin/perl/cpan/Pod-Parser/lib/Pod/PlainText.pm +++ b/gnu/usr.bin/perl/cpan/Pod-Parser/lib/Pod/PlainText.pm @@ -139,6 +139,19 @@ sub initialize { return $self->SUPER::initialize; } +# pod2text and pod2man re-use the same parser on a list of files, +# and will lose some information if some intermediate documents produce +# unbalanced calls to begin_cmd/end_cmd. +# via r1.4 of OpenBSD src/gnu/usr.bin/perl/lib/Pod/PlainText.pm +sub begin_pod { + my $self = shift; + + $$self{VERBATIM} = 0; + $$self{EXCLUDE} = 0; + + return $self->SUPER::begin_pod(@_); +} + ############################################################################ # Core overrides diff --git a/gnu/usr.bin/perl/cpan/Sys-Syslog/Makefile.PL b/gnu/usr.bin/perl/cpan/Sys-Syslog/Makefile.PL index 347197ab440..fce84965200 100644 --- a/gnu/usr.bin/perl/cpan/Sys-Syslog/Makefile.PL +++ b/gnu/usr.bin/perl/cpan/Sys-Syslog/Makefile.PL @@ -13,7 +13,7 @@ if ($] < 5.008) { } # create a lib/ dir in order to avoid warnings in Test::Distribution -mkdir "lib", 0755; +mkdir "lib", $ENV{PERL_CORE} ? 0770 : 0755; # virtual paths given to EU::MM my %virtual_path = ( 'Syslog.pm' => '$(INST_LIBDIR)/Syslog.pm' ); diff --git a/gnu/usr.bin/perl/cpan/Text-Balanced/lib/Text/Balanced.pm b/gnu/usr.bin/perl/cpan/Text-Balanced/lib/Text/Balanced.pm index f1a5780a0b9..4fbb1bc6315 100644 --- a/gnu/usr.bin/perl/cpan/Text-Balanced/lib/Text/Balanced.pm +++ b/gnu/usr.bin/perl/cpan/Text-Balanced/lib/Text/Balanced.pm @@ -1508,7 +1508,7 @@ C<extract_tagged> returns the complete text up to the point of failure. If the string is "PARA", C<extract_tagged> returns only the first paragraph after the tag (up to the first line that is either empty or contains only whitespace characters). -If the string is "", the the default behaviour (i.e. failure) is reinstated. +If the string is "", the default behaviour (i.e. failure) is reinstated. For example, suppose the start tag "/para" introduces a paragraph, which then continues until the next "/endpara" tag or until another "/para" tag is diff --git a/gnu/usr.bin/perl/cpan/podlators/lib/Pod/Man.pm b/gnu/usr.bin/perl/cpan/podlators/lib/Pod/Man.pm index b739559551d..f014b3183e9 100644 --- a/gnu/usr.bin/perl/cpan/podlators/lib/Pod/Man.pm +++ b/gnu/usr.bin/perl/cpan/podlators/lib/Pod/Man.pm @@ -896,6 +896,8 @@ sub devise_title { $cut = $i + 1; $cut++ if ($dirs[$i + 1] && $dirs[$i + 1] eq 'lib'); last; + } elsif ($dirs[$i] eq 'lib' && $dirs[$i + 1] && $dirs[0] eq 'ext') { + $cut = $i + 1; } } if ($cut > 0) { diff --git a/gnu/usr.bin/perl/cpan/podlators/scripts/pod2man.PL b/gnu/usr.bin/perl/cpan/podlators/scripts/pod2man.PL index f40c126e562..ea7070f7d63 100644 --- a/gnu/usr.bin/perl/cpan/podlators/scripts/pod2man.PL +++ b/gnu/usr.bin/perl/cpan/podlators/scripts/pod2man.PL @@ -77,7 +77,7 @@ Getopt::Long::config ('bundling_override'); GetOptions (\%options, 'center|c=s', 'date|d=s', 'errors=s', 'fixed=s', 'fixedbold=s', 'fixeditalic=s', 'fixedbolditalic=s', 'help|h', 'lax|l', 'name|n=s', 'nourls', 'official|o', 'quotes|q=s', - 'release|r=s', 'section|s=s', 'stderr', 'verbose|v', 'utf8|u') + 'release|r=s', 'section|s=s', 'stderr', 'verbose|v', 'utf8|u!') or exit 1; pod2usage (0) if $options{help}; @@ -123,7 +123,7 @@ exit $status; __END__ =for stopwords -en em --stderr stderr --utf8 UTF-8 overdo markup MT-LEVEL Allbery Solaris +en em --stderr stderr --no-utf8 UTF-8 overdo markup MT-LEVEL Allbery Solaris URL troff troff-specific formatters uppercased Christiansen --nourls UTC prepend @@ -137,7 +137,7 @@ pod2man [B<--center>=I<string>] [B<--date>=I<string>] [B<--errors>=I<style>] [B<--fixed>=I<font>] [B<--fixedbold>=I<font>] [B<--fixeditalic>=I<font>] [B<--fixedbolditalic>=I<font>] [B<--name>=I<name>] [B<--nourls>] [B<--official>] [B<--quotes>=I<quotes>] [B<--release>=I<version>] - [B<--section>=I<manext>] [B<--stderr>] [B<--utf8>] [B<--verbose>] + [B<--section>=I<manext>] [B<--stderr>] [B<--no-utf8>] [B<--verbose>] [I<input> [I<output>] ...] pod2man B<--help> @@ -323,19 +323,10 @@ to C<--errors=stderr> and is supported for backward compatibility. =item B<-u>, B<--utf8> -By default, B<pod2man> produces the most conservative possible *roff -output to try to ensure that it will work with as many different *roff -implementations as possible. Many *roff implementations cannot handle -non-ASCII characters, so this means all non-ASCII characters are converted -either to a *roff escape sequence that tries to create a properly accented -character (at least for troff output) or to C<X>. - -This option says to instead output literal UTF-8 characters. If your -*roff implementation can handle it, this is the best output format to use -and avoids corruption of documents containing non-ASCII characters. -However, be warned that *roff source with literal UTF-8 characters is not -supported by many implementations and may even result in segfaults and -other bad behavior. +This option allows B<pod2man> to output literal UTF-8 characters. +On OpenBSD, it is enabled by default and can be disabled with +B<--no-utf8>, in which case non-ASCII characters are converted +either to *roff escape sequences or to C<X>. Be aware that, when using this option, the input encoding of your POD source should be properly declared unless it's US-ASCII. Pod::Simple will |