mirror of
https://github.com/Kicksecure/security-misc.git
synced 2025-01-08 10:27:52 -05: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
|
local arr file_name existing_mode existing_owner existing_group
|
||||||
file_name="${line}"
|
file_name="${line}"
|
||||||
stat_output="$(stat -c "%a %U %G" "${line}")"
|
## Capture the stat output with fields separated by NUL characters.
|
||||||
read -r -a arr <<< "${stat_output}"
|
## Delimiter at the end to avoid the last field to be interpreted as having a newline.
|
||||||
existing_mode="${arr[0]}"
|
stat_output=$(stat -c '%n\0%a\0%U\0%G\0%' "${line}")
|
||||||
existing_owner="${arr[1]}"
|
readarray -d '\0' -t arr <<< "${stat_output}"
|
||||||
existing_group="${arr[2]}"
|
file_name_from_stat="${arr[0]}"
|
||||||
|
existing_mode="${arr[1]}"
|
||||||
|
existing_owner="${arr[2]}"
|
||||||
|
existing_group="${arr[3]}"
|
||||||
|
|
||||||
if test "${#arr[@]}" = 0; then
|
if test "${#arr[@]}" = 0; then
|
||||||
log error "Line is empty: '${line}'" >&2
|
log error "Line is empty: '${line}'" >&2
|
||||||
@ -363,7 +366,7 @@ set_file_perms() {
|
|||||||
|
|
||||||
local stat_output
|
local stat_output
|
||||||
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
|
log error "Failed to run 'stat' on file: '${fso_without_trailing_slash}'!" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user