diff --git a/usr/bin/permission-hardener b/usr/bin/permission-hardener index 2800e73..36c21f1 100755 --- a/usr/bin/permission-hardener +++ b/usr/bin/permission-hardener @@ -74,11 +74,14 @@ add_nosuid_statoverride_entry() { local arr file_name existing_mode existing_owner existing_group file_name="${line}" - stat_output="$(stat -c "%a %U %G" "${line}")" - read -r -a arr <<< "${stat_output}" - existing_mode="${arr[0]}" - existing_owner="${arr[1]}" - existing_group="${arr[2]}" + ## Capture the stat output with fields separated by NUL characters. + ## Delimiter at the end to avoid the last field to be interpreted as having a newline. + stat_output=$(stat -c '%n\0%a\0%U\0%G\0%' "${line}") + readarray -d '\0' -t arr <<< "${stat_output}" + file_name_from_stat="${arr[0]}" + existing_mode="${arr[1]}" + existing_owner="${arr[2]}" + existing_group="${arr[3]}" if test "${#arr[@]}" = 0; then log error "Line is empty: '${line}'" >&2 @@ -363,7 +366,7 @@ set_file_perms() { local stat_output stat_output="" - if ! stat_output="$(stat -c "%a %U %G" "${fso_without_trailing_slash}")"; then + if ! stat_output="$(stat -c '%n\0%a\0%U\0%G\0%' "${fso_without_trailing_slash}")"; then log error "Failed to run 'stat' on file: '${fso_without_trailing_slash}'!" >&2 continue fi