From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 14/18] initscripts fkt: Check for invalid values in readhash Date: Sun, 16 Jun 2024 18:02:41 +0200 Message-ID: <20240616160245.18865-15-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8566251778316694188==" List-Id: --===============8566251778316694188== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Jonatan Schlag --- 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/functi= ons index bbcfab95d..ce9d2a5ad 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -920,6 +920,12 @@ readhash() { continue fi =20 + # Skip lines with invalid values + if ! [[ ${val} =3D~ ^[\'][\ A-Za-z0-9=3D/,.:%_@#+-]*[\']$ ]] && ! [[ ${val= } =3D~ ^[A-Za-z0-9=3D/,.:%_@#+-]*$ ]]; 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/initsc= ripts/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=3D3 -GREEN_DEV=3Dgreen0 -GREEN_MACADDR=3D00:c0:08:8a:a0:47 -GREEN_DRIVER=3Dr8175 +CONFIG_TYPE=3D?3 +GREEN_DEV=3Dgree!n0 +GREEN_MACADDR=3D00:c0:08:8a :a0:47 +GREEN_DRIVER=3D"r8175" -RED_DEV=3Dred0 RE??D_MACADDR=3D00:c0:08:8a:a0:56 RED&&_DRIVER=3Dr8283 diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/te= sts/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' --=20 2.39.2 --===============8566251778316694188==--