Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/initscripts/system/functions | 6 ++++++ tests/src/initscripts/system/functions/data/2 | 8 ++++---- .../src/initscripts/system/functions/data/2_output_stderr | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index bbcfab95d..ce9d2a5ad 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -920,6 +920,12 @@ readhash() { continue fi
+ # Skip lines with invalid values + if ! [[ ${val} =~ ^['][\ A-Za-z0-9=/,.:%_@#+-]*[']$ ]] && ! [[ ${val} =~ ^[A-Za-z0-9=/,.:%_@#+-]*$ ]]; then + echo "Invalid value '${val}' for key '${key}'" >&2 + continue + fi + printf -v "${array}[${key}]" "%s" "${val}" done < "${file}" } diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initscripts/system/functions/data/2 index 3e1a7028b..3060ad880 100644 --- a/tests/src/initscripts/system/functions/data/2 +++ b/tests/src/initscripts/system/functions/data/2 @@ -1,7 +1,7 @@ -CONFIG_TYPE=3 -GREEN_DEV=green0 -GREEN_MACADDR=00:c0:08:8a:a0:47 -GREEN_DRIVER=r8175 +CONFIG_TYPE=?3 +GREEN_DEV=gree!n0 +GREEN_MACADDR=00:c0:08:8a :a0:47 +GREEN_DRIVER="r8175" -RED_DEV=red0 RE??D_MACADDR=00:c0:08:8a:a0:56 RED&&_DRIVER=r8283 diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/tests/src/initscripts/system/functions/data/2_output_stderr index dfcf2154b..f29e94b19 100644 --- a/tests/src/initscripts/system/functions/data/2_output_stderr +++ b/tests/src/initscripts/system/functions/data/2_output_stderr @@ -1,3 +1,7 @@ +Invalid value '?3' for key 'CONFIG_TYPE' +Invalid value 'gree!n0' for key 'GREEN_DEV' +Invalid value '00:c0:08:8a :a0:47' for key 'GREEN_MACADDR' +Invalid value '"r8175"' for key 'GREEN_DRIVER' Invalid key '-RED_DEV' Invalid key 'RE??D_MACADDR' Invalid key 'RED&&_DRIVER'