]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
initscripts: readhash: Fix handling = signs
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Dec 2024 16:42:17 +0000 (16:42 +0000)
committerArne Fitzenreiter <arne_f@ipfire.org>
Wed, 18 Dec 2024 07:14:06 +0000 (08:14 +0100)
The function expected that a line only contains exactly one equals sign
(=) which is not fit for purpose. In the WireGuard code we hold key
material that is encoded in base64 and therefore contains padding that
uses =.

This patch fixes that we expect exactly one equals sign immediately
after the key and we will then accept more = in the value - which was
already permitted.

Furthermore, this patch fixes the splitting if the key and value at the
first =.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
src/initscripts/system/functions
tests/src/initscripts/system/functions/data/2_output_stderr

index 094e3549562c08d94a21507510321f39902c68d5..e486cc085f52ac36bca64dfded5ac3baab538d45 100644 (file)
@@ -909,21 +909,15 @@ readhash() {
                        continue
                fi
 
-               # Skip lines without a =
-               if ! [[ ${line} =~ [^=]*=[^=]*$ ]]; then
+               # Check for a valid key followed by =
+               if ! [[ ${line} =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
                        echo "Invalid line '${line}'" >&2
                        continue
                fi
 
-               local key="${line%=*}"
+               local key="${line%%=*}"
                local val="${line#*=}"
 
-               # Skip lines with an invalid key
-               if ! [[ ${key} =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
-                       echo "Invalid key '${key}'" >&2
-                       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
index 82f035e26da282dd4ba61dcf7073714ae39e093b..7f4c5a94450c8443aefe75cb665ea4c059d834a4 100644 (file)
@@ -2,8 +2,8 @@ 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'
-Invalid key '0BLUE_DEV'
+Invalid line '-RED_DEV=red0'
+Invalid line 'RE??D_MACADDR=00:c0:08:8a:a0:56'
+Invalid line 'RED&&_DRIVER=r8283'
+Invalid line '0BLUE_DEV='blue0 net0''
 Invalid line 'Line_without_a_equal_sign_is_also_invalid'