From owner-svn-src-head@FreeBSD.ORG Sun Aug 29 11:56:56 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A157C106566B; Sun, 29 Aug 2010 11:56:56 +0000 (UTC) (envelope-from brian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 914018FC19; Sun, 29 Aug 2010 11:56:56 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7TBuurk063402; Sun, 29 Aug 2010 11:56:56 GMT (envelope-from brian@svn.freebsd.org) Received: (from brian@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7TBuu9B063397; Sun, 29 Aug 2010 11:56:56 GMT (envelope-from brian@svn.freebsd.org) Message-Id: <201008291156.o7TBuu9B063397@svn.freebsd.org> From: Brian Somers Date: Sun, 29 Aug 2010 11:56:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211963 - in head: bin/pax tools/regression/bin/pax X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Aug 2010 11:56:56 -0000 Author: brian Date: Sun Aug 29 11:56:56 2010 New Revision: 211963 URL: http://svn.freebsd.org/changeset/base/211963 Log: Correct an out-by-one error when earlying out ustar filenames that are too long. Filenames escaping this test are caught later on, so the bug doesn't cause any breakage. Document the correct ustar limitations in pax. As I have no access to the IEEE 1003.2 spec, I can only assume that the limitations imposed are in fact correct. Add regression tests for the filename limitations imposed by pax. MFC after: 3 weeks Added: head/tools/regression/bin/pax/ head/tools/regression/bin/pax/Makefile (contents, props changed) head/tools/regression/bin/pax/regress.t (contents, props changed) Modified: head/bin/pax/pax.1 head/bin/pax/tar.c Modified: head/bin/pax/pax.1 ============================================================================== --- head/bin/pax/pax.1 Sun Aug 29 11:32:41 2010 (r211962) +++ head/bin/pax/pax.1 Sun Aug 29 11:56:56 2010 (r211963) @@ -748,7 +748,9 @@ The extended tar interchange format spec .St -p1003.2 standard. The default blocksize for this format is 10240 bytes. -Pathnames stored by this format must be 250 characters or less in length. +Pathnames stored by this format must be 255 characters or less in length. +The directory part may be at most 155 characters and each path component +must be less than 100 characters. .El .Pp The Modified: head/bin/pax/tar.c ============================================================================== --- head/bin/pax/tar.c Sun Aug 29 11:32:41 2010 (r211962) +++ head/bin/pax/tar.c Sun Aug 29 11:56:56 2010 (r211963) @@ -1086,7 +1086,7 @@ name_split(char *name, int len) */ if (len <= TNMSZ) return(name); - if (len > (TPFSZ + TNMSZ + 1)) + if (len > TPFSZ + TNMSZ) return(NULL); /* Added: head/tools/regression/bin/pax/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/pax/Makefile Sun Aug 29 11:56:56 2010 (r211963) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +test: + prove -vmw regress.t + +clean: + rm -rf ustar-pathnames-[12] + rm -f ustar.ok ustar.fail* Added: head/tools/regression/bin/pax/regress.t ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/pax/regress.t Sun Aug 29 11:56:56 2010 (r211963) @@ -0,0 +1,91 @@ +#! /usr/bin/perl +# +# $FreeBSD$ + +use strict; +use warnings; + +use Test::More tests => 6; +use File::Path qw(rmtree mkpath); +use Cwd; + +my $n = 0; +sub create_file { + my $fn = shift; + + $n++; + (my $dir = $fn) =~ s,/[^/]+$,,; + mkpath $dir; + open my $fd, ">", $fn or die "$fn: $!"; + print $fd "file $n\n"; +} + + +ustar_pathnames: { SKIP: { + # Prove that pax breaks up ustar pathnames properly + + my $top = getcwd . "/ustar-pathnames-1"; + skip "Current path is too long", 6 if length $top > 92; + rmtree $top; + my $subdir = "x" . "x" x (92 - length $top); + my $work94 = "$top/$subdir"; + mkpath $work94; # $work is 94 characters long + + my $x49 = "x" x 49; + my $x50 = "x" x 50; + my $x60 = "x" x 60; + my $x95 = "x" x 95; + + my @paths = ( + "$work94/x099", # 99 chars + "$work94/xx100", # 100 chars + "$work94/xxx101", # 101 chars + "$work94/$x49/${x50}x199", # 199 chars + "$work94/$x49/${x50}xx200", # 200 chars + "$work94/$x49/${x50}xxx201", # 201 chars + "$work94/$x60/${x95}254", # 254 chars + "$work94/$x60/${x95}x255", # 255 chars + ); + + my @l = map { length } @paths; + + my $n = 0; + create_file $_ for @paths; + system "pax -wf ustar.ok $work94"; + ok($? == 0, "Wrote 'ustar.ok' containing files with lengths @l"); + + (my $orig = $top) =~ s,1$,2,; + rmtree $orig; + rename $top, $orig; + + system "pax -rf ustar.ok"; + ok($? == 0, "Restored 'ustar.ok' containing files with lengths @l"); + + system "diff -ru $orig $top"; + ok($? == 0, "Restored files are identical"); + + rmtree $top; + rename $orig, $top; + + # 256 chars (with components < 100 chars) should not work + push @paths, "$work94/x$x60/${x95}x256"; # 256 chars + push @l, length $paths[-1]; + create_file $paths[-1]; + system "pax -wf ustar.fail1 $work94"; + ok($?, "Failed to write 'ustar.fail1' containing files with lengths @l"); + + # Components with 100 chars shouldn't work + unlink $paths[-1]; + $paths[-1] = "$work94/${x95}xc100"; # 100 char filename + $l[-1] = length $paths[-1]; + create_file $paths[-1]; + system "pax -wf ustar.fail2 $work94"; + ok($?, "Failed to write 'ustar.fail2' with a 100 char filename"); + + unlink $paths[-1]; + $paths[-1] = "$work94/${x95}xc100/x"; # 100 char component + $l[-1] = length $paths[-1]; + create_file $paths[-1]; + system "pax -wf ustar.fail3 $work94"; + ok($?, "Failed to write 'ustar.fail3' with a 100 char component"); +}}