Skip to content

Commit 15b1541

Browse files
committed
Use realpath for permissions check, to test real files and not symlinks
Fixes #127
1 parent 169ca73 commit 15b1541

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

ada/ada

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ set_defaults() {
337337
for configfile in "${configfiles[@]}" ; do
338338
if [ -f "$configfile" ] ; then
339339
# Before loading, check permissions. Source file must never be world writable!
340-
permissions=$(get_permissions "$configfile") || exit 1
340+
real_configfile=$(realpath "$configfile")
341+
permissions=$(get_permissions "$real_configfile") || exit 1
341342
if grep '^........w.$' <<<"$permissions" ; then
342-
echo 1>&2 "ERROR: Config file '$configfile' is world writable. This is a security risk."
343+
echo 1>&2 "ERROR: Config file '$real_configfile' is world writable. This is a security risk."
343344
exit 1
344345
fi
345346
source "$configfile"
@@ -2100,13 +2101,14 @@ validate_input() {
21002101
exit 1
21012102
fi
21022103
# Tokenfile must never be world readable or writable!
2103-
if get_permissions "$tokenfile" | grep '^........w.$' ; then
2104-
echo 1>&2 "ERROR: Tokenfile '$tokenfile' is world writable." \
2104+
real_tokenfile=$(realpath "$tokenfile")
2105+
if get_permissions "$real_tokenfile" | grep '^........w.$' ; then
2106+
echo 1>&2 "ERROR: Tokenfile '$real_tokenfile' is world writable." \
21052107
"This may be unsafe on shared systems. Use chmod to change the permissions."
21062108
exit 1
21072109
fi
2108-
if get_permissions "$tokenfile" | grep '^.......r..$' ; then
2109-
echo 1>&2 "ERROR: Tokenfile '$tokenfile' is world readable." \
2110+
if get_permissions "$real_tokenfile" | grep '^.......r..$' ; then
2111+
echo 1>&2 "ERROR: Tokenfile '$real_tokenfile' is world readable." \
21102112
"This may be unsafe on shared systems. Use chmod to change the permissions."
21112113
exit 1
21122114
fi
@@ -2144,13 +2146,14 @@ validate_input() {
21442146
exit 1
21452147
fi
21462148
# Curl's netrc file shouldn't be world readable or writable!
2147-
if get_permissions "$netrcfile" | grep '^........w.$' ; then
2148-
echo 1>&2 "ERROR: Curl's config file '$netrcfile' is world writable." \
2149+
real_netrcfile=$(realpath "$netrcfile")
2150+
if get_permissions "$real_netrcfile" | grep '^........w.$' ; then
2151+
echo 1>&2 "ERROR: Curl's config file '$real_netrcfile' is world writable." \
21492152
"This may be unsafe on shared systems. Use chmod to change the permissions."
21502153
exit 1
21512154
fi
2152-
if get_permissions "$netrcfile" | grep '^.......r..$' ; then
2153-
echo 1>&2 "ERROR: Curl's config file '$netrcfile' is world readable." \
2155+
if get_permissions "$real_netrcfile" | grep '^.......r..$' ; then
2156+
echo 1>&2 "ERROR: Curl's config file '$real_netrcfile' is world readable." \
21542157
"This may be unsafe on shared systems. Use chmod to change the permissions."
21552158
exit 1
21562159
fi

0 commit comments

Comments
 (0)