Wed May 1 18:29:20 2019 UTC ()
bootstrap: prevent pkgsrcdir, prefix and wrkdir from being symlinks


(rillig)
diff -r1.262 -r1.263 pkgsrc/bootstrap/bootstrap

cvs diff -r1.262 -r1.263 pkgsrc/bootstrap/bootstrap (expand / switch to unified diff)

--- pkgsrc/bootstrap/bootstrap 2019/04/10 08:24:03 1.262
+++ pkgsrc/bootstrap/bootstrap 2019/05/01 18:29:20 1.263
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1#! /bin/sh 1#! /bin/sh
2 2
3# $NetBSD: bootstrap,v 1.262 2019/04/10 08:24:03 adam Exp $ 3# $NetBSD: bootstrap,v 1.263 2019/05/01 18:29:20 rillig Exp $
4# 4#
5# Copyright (c) 2001-2011 Alistair Crooks <agc@NetBSD.org> 5# Copyright (c) 2001-2011 Alistair Crooks <agc@NetBSD.org>
6# All rights reserved. 6# All rights reserved.
7# 7#
8# Redistribution and use in source and binary forms, with or without 8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions 9# modification, are permitted provided that the following conditions
10# are met: 10# are met:
11# 1. Redistributions of source code must retain the above copyright 11# 1. Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer. 12# notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright 13# 2. Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the 14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution. 15# documentation and/or other materials provided with the distribution.
16# 16#
@@ -334,37 +334,66 @@ copy_src() @@ -334,37 +334,66 @@ copy_src()
334 if [ -f $wrkdir/$_dst/config.guess ]; then 334 if [ -f $wrkdir/$_dst/config.guess ]; then
335 $cpprog $pkgsrcdir/mk/gnu-config/config.guess $wrkdir/$_dst/ 335 $cpprog $pkgsrcdir/mk/gnu-config/config.guess $wrkdir/$_dst/
336 fi 336 fi
337 if [ -f $wrkdir/$_dst/config.sub ]; then 337 if [ -f $wrkdir/$_dst/config.sub ]; then
338 $cpprog $pkgsrcdir/mk/gnu-config/config.sub $wrkdir/$_dst/ 338 $cpprog $pkgsrcdir/mk/gnu-config/config.sub $wrkdir/$_dst/
339 fi 339 fi
340} 340}
341 341
342get_optarg() 342get_optarg()
343{ 343{
344 expr "x$1" : "x[^=]*=\\(.*\\)" 344 expr "x$1" : "x[^=]*=\\(.*\\)"
345} 345}
346 346
347checkarg_sane_absolute_path() { 347checkarg_sane_absolute_path()
 348{
348 case "$1" in 349 case "$1" in
349 "") ;; # the default value will be used. 350 "") ;; # the default value will be used.
350 *[!-A-Za-z0-9_./]*) 351 *[!-A-Za-z0-9_./]*)
351 die "ERROR: Invalid characters in path $1 (from $2)." ;; 352 die "ERROR: Invalid characters in path $1 (from $2)." ;;
352 */) die "ERROR: The argument to $2 must not end in /." ;; 353 */) die "ERROR: The argument to $2 must not end in /." ;;
353 /*) ;; 354 *//* | */. | */./* | */.. | */../*)
 355 die "ERROR: The path $1 (from $2) must be canonical." ;;
 356 /*) checkarg_no_symlink_path "$1" "$2" ;;
354 *) die "ERROR: The argument to $2 must be an absolute path." ;; 357 *) die "ERROR: The argument to $2 must be an absolute path." ;;
355 esac 358 esac
356} 359}
357 360
 361checkarg_no_symlink_path()
 362{
 363 _dir=$1
 364 while [ ! -d "$_dir" ]; do
 365 _dir=${_dir%/*}
 366 done
 367
 368 _realdir=`cd "$_dir" && exec pwd`
 369 [ "$_realdir" = "$_dir" ] && return
 370
 371 die "ERROR: The path $1 (from $2) must not contain symlinks.
 372
 373 Given path : $1
 374 Resolved path: $_realdir${1##${_dir}}
 375
 376 Several packages assume that the given path of $2 stays the same when
 377 symlinks are resolved. When that assumption fails, they will:
 378
 379 * not find some include files or libraries during the build phase
 380 since the files from dependencies are not installed in
 381 \${WRKDIR}/.buildlink.
 382
 383 * install their files into the wrong path inside \${WRKDIR}/.destdir,
 384 which will fail the PLIST check during the install phase."
 385}
 386
358checkarg_sane_relative_path() { 387checkarg_sane_relative_path() {
359 case "$1" in 388 case "$1" in
360 "") ;; # the default value will be used. 389 "") ;; # the default value will be used.
361 *[!-A-Za-z0-9_./]*) 390 *[!-A-Za-z0-9_./]*)
362 die "ERROR: Invalid characters in path $1 (from $2)." ;; 391 die "ERROR: Invalid characters in path $1 (from $2)." ;;
363 /*) die "ERROR: The argument to $2 must be a relative path." ;; 392 /*) die "ERROR: The argument to $2 must be a relative path." ;;
364 *) ;; 393 *) ;;
365 esac 394 esac
366} 395}
367 396
368bootstrap_sh=${SH-/bin/sh} 397bootstrap_sh=${SH-/bin/sh}
369bootstrap_sh_set=${SH+set} 398bootstrap_sh_set=${SH+set}
370 399
@@ -459,33 +488,33 @@ while [ $# -gt 0 ]; do @@ -459,33 +488,33 @@ while [ $# -gt 0 ]; do
459 binary_macpkg="$2"; shift ;; 488 binary_macpkg="$2"; shift ;;
460 --make-jobs=*) make_jobs=`get_optarg "$1"` ;; 489 --make-jobs=*) make_jobs=`get_optarg "$1"` ;;
461 --make-jobs) make_jobs="$2"; shift ;; 490 --make-jobs) make_jobs="$2"; shift ;;
462 --full) full=yes ;; 491 --full) full=yes ;;
463 --quiet) quiet=yes ;; 492 --quiet) quiet=yes ;;
464 --help) echo "$usage"; exit ;; 493 --help) echo "$usage"; exit ;;
465 -h) echo "$usage"; exit ;; 494 -h) echo "$usage"; exit ;;
466 -*) echo "${0##*/}: unknown option \"$1\"" 1>&2 495 -*) echo "${0##*/}: unknown option \"$1\"" 1>&2
467 echo "$usage" 1>&2; exit 1 ;; 496 echo "$usage" 1>&2; exit 1 ;;
468 esac 497 esac
469 shift 498 shift
470done 499done
471 500
472checkarg_sane_absolute_path "$wrkdir" "--workdir" 
473checkarg_sane_absolute_path "$prefix" "--prefix" 501checkarg_sane_absolute_path "$prefix" "--prefix"
474checkarg_sane_absolute_path "$pkgdbdir" "--pkgdbdir" 502checkarg_sane_absolute_path "$pkgdbdir" "--pkgdbdir"
475checkarg_sane_absolute_path "$sysconfdir" "--sysconfdir" 503checkarg_sane_absolute_path "$sysconfdir" "--sysconfdir"
476checkarg_sane_absolute_path "$varbase" "--varbase" 504checkarg_sane_absolute_path "$varbase" "--varbase"
477checkarg_sane_relative_path "$pkginfodir" "--pkginfodir" 505checkarg_sane_relative_path "$pkginfodir" "--pkginfodir"
478checkarg_sane_relative_path "$pkgmandir" "--pkgmandir" 506checkarg_sane_relative_path "$pkgmandir" "--pkgmandir"
 507checkarg_sane_absolute_path "$wrkdir" "--workdir"
479 508
480# set defaults for system locations if not already set by the user 509# set defaults for system locations if not already set by the user
481wrkobjdir=${wrkdir}/pkgsrc 510wrkobjdir=${wrkdir}/pkgsrc
482if [ "$unprivileged" = "yes" ]; then 511if [ "$unprivileged" = "yes" ]; then
483 [ -z "$prefix" ] && prefix=${HOME}/pkg 512 [ -z "$prefix" ] && prefix=${HOME}/pkg
484elif [ -z "$prefix" -o "$prefix" = "/usr/pkg" ]; then 513elif [ -z "$prefix" -o "$prefix" = "/usr/pkg" ]; then
485 prefix=/usr/pkg 514 prefix=/usr/pkg
486 [ -z "$varbase" ] && varbase=/var 515 [ -z "$varbase" ] && varbase=/var
487fi 516fi
488 517
489[ -z "$varbase" ] && varbase=${prefix}/var 518[ -z "$varbase" ] && varbase=${prefix}/var
490[ -z "$pkgdbdir" ] && pkgdbdir=${prefix}/pkgdb 519[ -z "$pkgdbdir" ] && pkgdbdir=${prefix}/pkgdb
491 520