From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH 18/21] initscripts fkt: readhash should only parse lines with a = Date: Mon, 20 May 2024 11:06:08 +0200 Message-ID: <20240520090611.10406-19-jonatan.schlag@ipfire.org> In-Reply-To: <20240520090611.10406-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3085139343605567673==" List-Id: --===============3085139343605567673== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable A line without a =3D is clearly invalid. Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 6 ++++++ tests/src/initscripts/system/functions/data/2 | 1 + tests/src/initscripts/system/functions/data/2_output_stderr | 1 + 3 files changed, 8 insertions(+) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functi= ons index bbcfab95d..38a1316a8 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -911,6 +911,12 @@ readhash() { continue fi =20 + # Skip lines without a =3D + if ! [[ ${line} =3D~ [^=3D]*=3D[^=3D]*$ ]]; then + echo "Invalid line '${line}'" >&2 + continue + fi + local key=3D"${line%=3D*}" local val=3D"${line#*=3D}" =20 diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initsc= ripts/system/functions/data/2 index 3e1a7028b..d1c4d327d 100644 --- a/tests/src/initscripts/system/functions/data/2 +++ b/tests/src/initscripts/system/functions/data/2 @@ -15,6 +15,7 @@ RED_ADDRESS=3D0.0.0.0 RED_NETMASK=3D0.0.0.0 RED_TYPE=3DPPPOE RED_NETADDRESS=3D0.0.0.0 +Line_without_a_equal_sign_is_also_invalid =20 # Comment for testing =20 # Comment for testing Comments with spaces before 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..cccd19af6 100644 --- a/tests/src/initscripts/system/functions/data/2_output_stderr +++ b/tests/src/initscripts/system/functions/data/2_output_stderr @@ -2,3 +2,4 @@ Invalid key '-RED_DEV' Invalid key 'RE??D_MACADDR' Invalid key 'RED&&_DRIVER' Invalid key '0BLUE_DEV' +Invalid line 'Line_without_a_equal_sign_is_also_invalid' --=20 2.39.2 --===============3085139343605567673==--