From nobody@FreeBSD.org  Mon Jan 27 01:45:40 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id EB6C18F2
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Jan 2014 01:45:40 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id D42EA110D
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Jan 2014 01:45:40 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id s0R1jeHw050807
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Jan 2014 01:45:40 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id s0R1jeUU050798;
	Mon, 27 Jan 2014 01:45:40 GMT
	(envelope-from nobody)
Message-Id: <201401270145.s0R1jeUU050798@oldred.freebsd.org>
Date: Mon, 27 Jan 2014 01:45:40 GMT
From: David Shane Holden <dpejesh@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] freebsd-update -b: correctly handle symlinks with absolute paths
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         186152
>Category:       bin
>Synopsis:       [patch] freebsd-update(8): freebsd-update -b: correctly handle symlinks with absolute paths
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    cperciva
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 27 01:50:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Sun Apr 13 23:29:50 UTC 2014
>Originator:     David Shane Holden
>Release:        10.0-RELEASE
>Organization:
>Environment:
FreeBSD node 10.0-RELEASE FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014     root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
When upgrading a base directory (freebsd-update -b), symlinks with absolute paths are checked against the host system instead of the base directory which was causing the problem reported at https://forums.freebsd.org/viewtopic.php?f=5&t=44520.

>How-To-Repeat:
Check forums thread.
>Fix:


Patch attached with submission follows:

--- freebsd-update.orig	2014-01-27 01:03:59.000000000 +0000
+++ freebsd-update	2014-01-27 01:18:01.000000000 +0000
@@ -1437,11 +1437,21 @@
 	# sorted by device and inode number.
 	while read F; do
 		# If the symlink/file/directory does not exist, record this.
-		if ! [ -e ${BASEDIR}/${F} ]; then
+		# Symlinks with absolute paths need to be checked relative
+		# to their base directories.
+		FF=${F}
+		if [ -L ${BASEDIR}/${F} ]; then
+			LINK=`readlink ${BASEDIR}/${F}`
+			echo "${LINK}" | grep -qe "^/"
+			if [ $? -eq 0 ]; then
+				FF=${LINK}
+			fi
+		fi
+		if ! [ -e ${BASEDIR}/${FF} ]; then
 			echo "${F}|-||||||"
 			continue
 		fi
-		if ! [ -r ${BASEDIR}/${F} ]; then
+		if ! [ -r ${BASEDIR}/${FF} ]; then
 			echo "Cannot read file: ${BASEDIR}/${F}"	\
 			    >/dev/stderr
 			touch .err


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->cperciva 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Mon Jan 27 04:39:21 UTC 2014 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=186152 

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, dpejesh@yahoo.com
Cc:  
Subject: Re: bin/186152: [patch] freebsd-update -b: correctly handle symlinks
 with absolute paths
Date: Fri, 31 Jan 2014 23:49:59 +0100

 In PR bin/186152, you wrote:
 > When upgrading a base directory (freebsd-update -b), symlinks with
 > absolute paths are checked against the host system instead of the base
 > directory which was causing the problem reported at
 > https://forums.freebsd.org/viewtopic.php?f=5&t=44520.
 
 > +             # Symlinks with absolute paths need to be checked relative
 > +            # to their base directories.
 > +          FF=${F}
 > +               if [ -L ${BASEDIR}/${F} ]; then
 > +                       LINK=`readlink ${BASEDIR}/${F}`
 > +                       echo "${LINK}" | grep -qe "^/"
 > +                    if [ $? -eq 0 ]; then
 > +                         FF=${LINK}
 > +                    fi
 > +            fi
 
 Instead of the echo/grep stuff, please just do
 case `readlink "${BASEDIR}/${F}"` in
 /*) FF=${LINK}
 esac
 
 Also, this does not work if a symlink points to another symlink but I
 guess this does not happen in practice.
 
 -- 
 Jilles Tjoelker

From: David Shane Holden <dpejesh@yahoo.com>
To: Jilles Tjoelker <jilles@stack.nl>, bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/186152: [patch] freebsd-update -b: correctly handle symlinks
 with absolute paths
Date: Fri, 31 Jan 2014 23:07:31 -0500

 On 01/31/14 17:49, Jilles Tjoelker wrote:
 > In PR bin/186152, you wrote:
 >> When upgrading a base directory (freebsd-update -b), symlinks with
 >> absolute paths are checked against the host system instead of the base
 >> directory which was causing the problem reported at
 >> https://forums.freebsd.org/viewtopic.php?f=5&t=44520.
 >
 >> +             # Symlinks with absolute paths need to be checked relative
 >> +            # to their base directories.
 >> +          FF=${F}
 >> +               if [ -L ${BASEDIR}/${F} ]; then
 >> +                       LINK=`readlink ${BASEDIR}/${F}`
 >> +                       echo "${LINK}" | grep -qe "^/"
 >> +                    if [ $? -eq 0 ]; then
 >> +                         FF=${LINK}
 >> +                    fi
 >> +            fi
 >
 > Instead of the echo/grep stuff, please just do
 > case `readlink "${BASEDIR}/${F}"` in
 > /*) FF=${LINK}
 > esac
 
 Much better, I'm so accustomed to using bash that I wasn't quite sure
 how best to do it in sh and I couldn't find a better way.  I appreciate
 the feedback.
 
 >
 > Also, this does not work if a symlink points to another symlink but I
 > guess this does not happen in practice.
 >
 
 Nope, it doesn't.  I've updated the patch which should handle them 
 properly. 
 https://googledrive.com/host/0B0OQnKtejJEMSktRRjBUY1AwME0/freebsd-update.diff
 
Responsible-Changed-From-To: cperciva->cperciva 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Apr 13 23:27:34 UTC 2014 
Responsible-Changed-Why:  
fix synopsis. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=186152 
>Unformatted:
