mirror of
https://github.com/Kicksecure/security-misc.git
synced 2024-12-23 01:13:40 +07:00
modify call of stat to use NUL delimiter
for more robust string parsing
This commit is contained in:
parent
7200e9bd8c
commit
a077ae54ea
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user