From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH 19/21] initscripts fkt: Check for invalid values in readhash Date: Mon, 20 May 2024 11:06:09 +0200 Message-ID: <20240520090611.10406-20-jonatan.schlag@ipfire.org> In-Reply-To: <20240520090611.10406-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0003153017046226363==" List-Id: --===============0003153017046226363== 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 38a1316a8..c9c4c0675 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -926,6 +926,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 d1c4d327d..760294c30 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 cccd19af6..82f035e26 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 --===============0003153017046226363==--