Bug 186152 - [patch] freebsd-update(8): freebsd-update -b: correctly handle symlinks with absolute paths
Summary: [patch] freebsd-update(8): freebsd-update -b: correctly handle symlinks with ...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-27 01:50 UTC by David Shane Holden
Modified: 2019-03-12 23:00 UTC (History)
2 users (show)

See Also:


Attachments
file.diff (802 bytes, patch)
2014-01-27 01:50 UTC, David Shane Holden
no flags Details | Diff
freebsd-update.sh.diff (922 bytes, patch)
2018-05-30 23:50 UTC, David Shane Holden
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Shane Holden 2014-01-27 01:50:00 UTC
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.

Fix: Patch attached with submission follows:
How-To-Repeat: Check forums thread.
Comment 1 Xin LI freebsd_committer 2014-01-27 04:39:21 UTC
Responsible Changed
From-To: freebsd-bugs->cperciva

Over to maintainer.
Comment 2 Jilles Tjoelker freebsd_committer 2014-01-31 22:49:59 UTC
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
Comment 3 David Shane Holden 2014-02-01 04:07:31 UTC
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
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2014-04-14 00:27:34 UTC
Responsible Changed
From-To: cperciva->cperciva

fix synopsis.
Comment 5 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:49:25 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 6 David Shane Holden 2018-05-30 23:50:52 UTC
Created attachment 193855 [details]
freebsd-update.sh.diff
Comment 7 Gerald Aryeetey 2019-01-10 21:48:32 UTC
>+		while [ -L ${BASEDIR}/${FF} ]; do

This could cause a potential issue if circular links exist.
One solution to this would be to have limit traversal depth (to 10 or something).

Also you may want to consider renaming `FF` to something like `SOURCE_F` or `FOLLOWED_F`
Comment 8 Colin Percival freebsd_committer 2019-03-12 23:00:02 UTC
Drop freebsd-update PRs which were assigned to me.  I'm not working on this code any more.