From 49e867fab4c1bcb6549079e735abec2149e42cf6 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sat, 24 Oct 2020 15:59:25 +0200 Subject: [PATCH] [type/__uci_section] Add more parameter checks --- cdist/conf/type/__uci_section/manifest | 42 +++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/cdist/conf/type/__uci_section/manifest b/cdist/conf/type/__uci_section/manifest index 1a59b970..b5fa4a3b 100755 --- a/cdist/conf/type/__uci_section/manifest +++ b/cdist/conf/type/__uci_section/manifest @@ -19,11 +19,15 @@ # grep_line() { echo "$2" | grep -qxF "$1"; } +uci_validate_name() { + # like util.c uci_validate_name() + test -n "$*" && test -z "$(printf %s "$*" | tr -d '[:alnum:]_' | tr -c '' .)" +} +validate_options() { grep -shv -e '^[[:alnum:]_]\{1,\}=' "$@"; } unquote_lines() { sed -e '/^".*"$/{s/^"//;s/"$//}' \ -e '/'"^'.*'"'$/{s/'"^'"'//;s/'"'$"'//}' } - append_values() { while read -r _value do @@ -32,12 +36,23 @@ append_values() { unset _value "$@" &2 } + ## Check section name and error if invalid! case ${__object_id:?} in @@ -74,12 +89,6 @@ in type_is=$(cat "${__object:?}/explorer/type") type_should=$(cat "${__object:?}/parameter/type") - if test -f "${__object:?}/parameter/option" - then - optnames_should=$( - sed -e 's/=.*$//' "${__object:?}/parameter/option" | sort -u) - fi - if test -n "${type_is}" then if test "${type_is}" != "${type_should##*.}" @@ -105,6 +114,17 @@ in esac fi + # Check options for syntax errors + validate_options "${__object:?}/parameter/object" \ + | print_errors 'Found erroneous options in arguments:' + + # Collect option names + if test -f "${__object:?}/parameter/option" + then + optnames_should=$( + sed -e 's/=.*$//' "${__object:?}/parameter/option" | sort -u) + fi + # Make sure the section itself is present __uci "${section}" --state present --transaction "${transaction_name}" \ --value "${sect_type}"