~ubuntu-branches/ubuntu/precise/devscripts/precise-security

« back to all changes in this revision

Viewing changes to scripts/uscan.pl

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-01-10 13:02:15 UTC
  • Revision ID: package-import@ubuntu.com-20140110130215-5ykfnmn91d33frg2
Tags: 2.11.6ubuntu1.6
* SECURITY UPDATE: arbitrary code execution in uscan via crafted tarball
  - scripts/uscan.pl: improve tarball handling.
  - 02c6850d973e3e1246fde72edab27f03d63acc52
  - 4b7e58ee6000cdefac0682601cec6ecce0137467
  - CVE-2013-6888

Show diffs side-by-side

added added

removed removed

Lines of Context:
1345
1345
    if ($repack and $newfile_base =~ /^(.*)\.(tar\.bz2|tbz2?)$/) {
1346
1346
        print "-- Repacking from bzip2 to gzip\n" if $verbose;
1347
1347
        my $newfile_base_gz = "$1.tar.gz";
1348
 
        my $fname = tempfile(UNLINK => 1);
 
1348
        my (undef, $fname) = tempfile(UNLINK => 1);
1349
1349
        spawn(exec => ['bunzip2', '-c', "$destdir/$newfile_base"],
1350
1350
              to_file => $fname,
1351
1351
              wait_child => 1);
1360
1360
    if ($repack and $newfile_base =~ /^(.*)\.(tar\.lzma|tlz(?:ma?)?)$/) {
1361
1361
        print "-- Repacking from lzma to gzip\n" if $verbose;
1362
1362
        my $newfile_base_gz = "$1.tar.gz";
1363
 
        my $fname = tempfile(UNLINK => 1);
 
1363
        my (undef, $fname) = tempfile(UNLINK => 1);
1364
1364
        spawn(exec => ['xz', '-F', 'lzma', '-cd', "$destdir/$newfile_base"],
1365
1365
              to_file => $fname,
1366
1366
              wait_child => 1);
1375
1375
    if ($repack and $newfile_base =~ /^(.*)\.(tar\.xz|txz)$/) {
1376
1376
        print "-- Repacking from xz to gzip\n" if $verbose;
1377
1377
        my $newfile_base_gz = "$1.tar.gz";
1378
 
        my $fname = tempfile(UNLINK => 1);
 
1378
        my (undef, $fname) = tempfile(UNLINK => 1);
1379
1379
        spawn(exec => ['xz', '-cd', "$destdir/$newfile_base"],
1380
1380
              to_file => $fname,
1381
1381
              wait_child => 1);
1394
1394
          or die("unzip binary not found. You need to install the package unzip to be able to repack .zip upstream archives.\n");
1395
1395
 
1396
1396
        my $newfile_base_gz = "$1.tar.gz";
1397
 
        my $tempdir = tempdir ( "uscanXXXX", TMPDIR => 1, CLEANUP => 1 );
1398
 
        my $globpattern = "*";
1399
 
        my $hidden = ".[!.]*";
 
1397
        my $tempdir = tempdir ("uscanXXXX", TMPDIR => 1, CLEANUP => 1);
 
1398
        # Parent of the target directory should be under our control
 
1399
        $tempdir .= '/repack';
 
1400
        mkdir $tempdir or die("Unable to mkdir($tempdir): $!\n");
1400
1401
        my $absdestdir = abs_path($destdir);
1401
1402
        system('unzip', '-q', '-a', '-d', $tempdir, "$destdir/$newfile_base") == 0
1402
 
          or die("Repacking from zip to tar.gz failed (could not unzip)\n");
1403
 
        if (defined glob("$tempdir/$hidden")) {
1404
 
            $globpattern .= " $hidden";
 
1403
            or die("Repacking from zip to tar.gz failed (could not unzip)\n");
 
1404
        my $cwd = cwd();
 
1405
        chdir($tempdir) or die("Unable to chdir($tempdir): $!\n");
 
1406
        eval {
 
1407
            spawn(exec => ['tar', '--owner=root', '--group=root', '--mode=a+rX', '-czf', "$absdestdir/$newfile_base_gz", glob('* .[!.]*')],
 
1408
                  env => { GZIP => '-n -9' },
 
1409
                  wait_child => 1);
 
1410
        };
 
1411
        if ($@) {
 
1412
            die("Repacking from zip to tar.gz failed (could not create tarball)\n");
1405
1413
        }
1406
 
        system("cd $tempdir; GZIP='-n -9' tar --owner=root --group=root --mode=a+rX -czf \"$absdestdir/$newfile_base_gz\" $globpattern") == 0
1407
 
          or die("Repacking from zip to tar.gz failed (could not create tarball)\n");
 
1414
        chdir($cwd);
1408
1415
        unlink "$destdir/$newfile_base";
1409
1416
        $newfile_base = $newfile_base_gz;
1410
1417
    }
1413
1420
                             |tar\.bz2|tbz2?
1414
1421
                             |tar.lzma|tlz(?:ma?)?
1415
1422
                             |tar.xz|txz)$/x) {
1416
 
        my $filetype = `file -b -k \"$destdir/$newfile_base\"`;
1417
 
        unless ($filetype =~ /compressed data/) {
 
1423
        my $filetype;
 
1424
        eval {
 
1425
            spawn(exec => ['file', '-b', '-k', "$destdir/$newfile_base"],
 
1426
                  to_string => \$filetype,
 
1427
                  wait_child => 1);
 
1428
        };
 
1429
        unless (defined $filetype && $filetype =~ /compressed data/) {
1418
1430
            warn "$progname warning: $destdir/$newfile_base does not appear to be a compressed file;\nthe file command says: $filetype\nNot processing this file any further!\n";
1419
1431
            return 1;
1420
1432
        }