Skip to content

Commit 6ae7a1e

Browse files
committed
New global input validation method for object key-value strings [parse_object_kv_list]
1 parent 01334f1 commit 6ae7a1e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

func/main.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,35 @@ is_object_valid() {
246246
fi
247247
}
248248

249+
# Check if a object string with key values pairs has the correct format and load it afterwards
250+
parse_object_kv_list() {
251+
local str
252+
local objkv
253+
local suboutput
254+
local OLD_IFS="$IFS"
255+
256+
str=${@//$'\n'/ }
257+
str=${str//\"/\\\"}
258+
IFS=$'\n'
259+
260+
suboutput=$(sudo -u nobody bash -c "PS4=''; set -xe; eval \"${str}\"" 2>&1)
261+
check_result $? "Invalid object format: ${str}" $E_INVALID
262+
263+
for objkv in $suboutput; do
264+
265+
if [[ "$objkv" =~ ^'eval ' ]]; then
266+
continue
267+
fi
268+
269+
if ! [[ "$objkv" =~ ^([[:alnum:]][_[:alnum:]]{0,64}[[:alnum:]])=(\'?[^\']+?\'?)?$ ]]; then
270+
check_result $E_INVALID "Invalid key value format [$objkv]"
271+
fi
272+
273+
eval "$objkv"
274+
done
275+
IFS="$OLD_IFS"
276+
}
277+
249278
# Check if object is supended
250279
is_object_suspended() {
251280
if [ $2 = 'USER' ]; then

0 commit comments

Comments
 (0)