Message ID | 20240520090611.10406-19-jonatan.schlag@ipfire.org |
---|---|
State | New |
Headers |
Return-Path: <development-bounces@lists.ipfire.org> Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4VjWsr5CN7z3wxG for <patchwork@web04.haj.ipfire.org>; Mon, 20 May 2024 09:07:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4VjWsm1S2Lz5dv; Mon, 20 May 2024 09:07:08 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4VjWsN1ljGz32xd; Mon, 20 May 2024 09:06:48 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4VjWsK2DbHz331V for <development@lists.ipfire.org>; Mon, 20 May 2024 09:06:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4VjWsJ4mJQz4XG; Mon, 20 May 2024 09:06:44 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1716196004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d6CV/XcKOfMsW5i/miqVPSpfrqWXfoIhwwNjihFEYsk=; b=u/Q6aFXNszvkTMsqADxIEY+V35pkNW+aRj8y0FdA54/5C/wYo6IAGBnAFeIMJc3JNXriYR L16y9Ar/vOb5EdCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1716196004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d6CV/XcKOfMsW5i/miqVPSpfrqWXfoIhwwNjihFEYsk=; b=Dn/dcQnavVUVmHobAgU0Cyd0xtsl7EEI9UGic61BHyJxaeAu9mM5/xZ3hhh2CJYswG3FYi Qo3ybsZ3qNeJF7oJUtCrM9VbktkhhRwo21yyb1j9cfdMSUpd+mZT1YpLp48TxmFRbHBll1 eb3bR4L1XfiwmgtQGmkHkxy8bZnggDToiskv4uVEjPUtxN++mr7v1Dw/lGBqbK9GrGaHsb arbHFNmQ0IKb/Lzy3n8ROOm0EMoyM3mw3cEhE0GMfrYE2LOHZHBrEYfL4RMBcGStyTFEXS +XJ+uGHCiRsruQ3sR/wCm2PE44NTQ9DecfploMhs99y3gbd8jrVFfM+D4MNtfw== From: Jonatan Schlag <jonatan.schlag@ipfire.org> 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> References: <20240520090611.10406-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: LPDWIV3PBZZU2UFUHMDBXR5ZUF722YD5 X-Message-ID-Hash: LPDWIV3PBZZU2UFUHMDBXR5ZUF722YD5 X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk <development.lists.ipfire.org> Archived-At: <https://lists.ipfire.org/hyperkitty/list/development@lists.ipfire.org/message/LPDWIV3PBZZU2UFUHMDBXR5ZUF722YD5/> List-Archive: <https://lists.ipfire.org/hyperkitty/list/development@lists.ipfire.org/> List-Help: <mailto:development-request@lists.ipfire.org?subject=help> List-Owner: <mailto:development-owner@lists.ipfire.org> List-Post: <mailto:development@lists.ipfire.org> List-Subscribe: <mailto:development-join@lists.ipfire.org> List-Unsubscribe: <mailto:development-leave@lists.ipfire.org> |
Series |
[01/21] test: Add bash lib for colors
|
|
Commit Message
Jonatan Schlag
May 20, 2024, 9:06 a.m. UTC
A line without a = is clearly invalid.
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
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(+)
Comments
> On 20 May 2024, at 10:06, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > A line without a = is clearly invalid. > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > --- > 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/functions > index bbcfab95d..38a1316a8 100644 > --- a/src/initscripts/system/functions > +++ b/src/initscripts/system/functions > @@ -911,6 +911,12 @@ readhash() { > continue > fi > > + # Skip lines without a = > + if ! [[ ${line} =~ [^=]*=[^=]*$ ]]; then > + echo "Invalid line '${line}'" >&2 > + continue > + fi > + > local key="${line%=*}" > local val="${line#*=}" You can simply check if key and value have content. That should be a lot easier than whatever this is. > > diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initscripts/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=0.0.0.0 > RED_NETMASK=0.0.0.0 > RED_TYPE=PPPOE > RED_NETADDRESS=0.0.0.0 > +Line_without_a_equal_sign_is_also_invalid > > # Comment for testing > # Comment for testing Comments with spaces before > diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/tests/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' > -- > 2.39.2 >
Hi, Am Freitag, dem 31.05.2024 um 10:56 +0100 schrieb Michael Tremer: > > > > On 20 May 2024, at 10:06, Jonatan Schlag > > <jonatan.schlag@ipfire.org> wrote: > > > > A line without a = is clearly invalid. > > > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > > --- > > 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/functions > > index bbcfab95d..38a1316a8 100644 > > --- a/src/initscripts/system/functions > > +++ b/src/initscripts/system/functions > > @@ -911,6 +911,12 @@ readhash() { > > continue > > fi > > > > + # Skip lines without a = > > + if ! [[ ${line} =~ [^=]*=[^=]*$ ]]; then > > + echo "Invalid line '${line}'" >&2 > > + continue > > + fi > > + > > local key="${line%=*}" > > local val="${line#*=}" > > You can simply check if key and value have content. That should be a > lot easier than whatever this is. Hi, Unfortunately not. A line like Line_without_a_equal_sign_is_also_invalid result in an entry like this: Key = Line_without_a_equal_sign_is_also_invalid Value = Line_without_a_equal_sign_is_also_invalid We simply do not split without an equal sign, so key and value are equal. And maybe are also valid keys and values. Jonatan > > > > > diff --git a/tests/src/initscripts/system/functions/data/2 > > b/tests/src/initscripts/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=0.0.0.0 > > RED_NETMASK=0.0.0.0 > > RED_TYPE=PPPOE > > RED_NETADDRESS=0.0.0.0 > > +Line_without_a_equal_sign_is_also_invalid > > > > # Comment for testing > > # Comment for testing Comments with spaces before > > diff --git > > a/tests/src/initscripts/system/functions/data/2_output_stderr > > b/tests/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' > > -- > > 2.39.2 > > >
Hello, > On 2 Jun 2024, at 19:09, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > Hi, > > > Am Freitag, dem 31.05.2024 um 10:56 +0100 schrieb Michael Tremer: >> >> >>> On 20 May 2024, at 10:06, Jonatan Schlag >>> <jonatan.schlag@ipfire.org> wrote: >>> >>> A line without a = is clearly invalid. >>> >>> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> >>> --- >>> 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/functions >>> index bbcfab95d..38a1316a8 100644 >>> --- a/src/initscripts/system/functions >>> +++ b/src/initscripts/system/functions >>> @@ -911,6 +911,12 @@ readhash() { >>> continue >>> fi >>> >>> + # Skip lines without a = >>> + if ! [[ ${line} =~ [^=]*=[^=]*$ ]]; then >>> + echo "Invalid line '${line}'" >&2 >>> + continue >>> + fi >>> + >>> local key="${line%=*}" >>> local val="${line#*=}" >> >> You can simply check if key and value have content. That should be a >> lot easier than whatever this is. > > Hi, > > Unfortunately not. A line like > > Line_without_a_equal_sign_is_also_invalid Okay, let’s say this is indeed an empty line (and not just a key without a value). > result in an entry like this: > > Key = Line_without_a_equal_sign_is_also_invalid > Value = Line_without_a_equal_sign_is_also_invalid Yes, you can’t use the parameter expansions then and need to check first if you have an = character at all (you can simply do that with a case statement instead of a complicated regular expression. > We simply do not split without an equal sign, so key and value are > equal. And maybe are also valid keys and values. That isn’t a very good check. It could theoretically happen. -Michael > > Jonatan >> >>> >>> diff --git a/tests/src/initscripts/system/functions/data/2 >>> b/tests/src/initscripts/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=0.0.0.0 >>> RED_NETMASK=0.0.0.0 >>> RED_TYPE=PPPOE >>> RED_NETADDRESS=0.0.0.0 >>> +Line_without_a_equal_sign_is_also_invalid >>> >>> # Comment for testing >>> # Comment for testing Comments with spaces before >>> diff --git >>> a/tests/src/initscripts/system/functions/data/2_output_stderr >>> b/tests/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' >>> -- >>> 2.39.2 >>> >> >
diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index bbcfab95d..38a1316a8 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -911,6 +911,12 @@ readhash() { continue fi + # Skip lines without a = + if ! [[ ${line} =~ [^=]*=[^=]*$ ]]; then + echo "Invalid line '${line}'" >&2 + continue + fi + local key="${line%=*}" local val="${line#*=}" diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initscripts/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=0.0.0.0 RED_NETMASK=0.0.0.0 RED_TYPE=PPPOE RED_NETADDRESS=0.0.0.0 +Line_without_a_equal_sign_is_also_invalid # Comment for testing # Comment for testing Comments with spaces before diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/tests/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'