Config: Don't interpret file names as regular expressions

Message ID 20241207115051.3730583-1-michael.tremer@ipfire.org
State Accepted
Commit f2fce26932d86ac6e15ec33d58ae432958411410
Headers
Series Config: Don't interpret file names as regular expressions |

Commit Message

Michael Tremer Dec. 7, 2024, 11:50 a.m. UTC
  When we are searching for changes in rootfiles, we walk through each
file that we have found in the build and check if it exists in the
rootfile. That check interpreted filenames as regular expressions which
caused a problem in the case of "/usr/bin/[".

This patch changes that grep will only search for an exact string match
(-F) and the string must be the entire line (-x).

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 lfs/Config | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Adolf Belka Dec. 7, 2024, 1:04 p.m. UTC | #1
Reviewed-by: Adolf Belka <adolf.belka@ipfire.org>

On 07/12/2024 12:50, Michael Tremer wrote:
> When we are searching for changes in rootfiles, we walk through each
> file that we have found in the build and check if it exists in the
> rootfile. That check interpreted filenames as regular expressions which
> caused a problem in the case of "/usr/bin/[".
>
> This patch changes that grep will only search for an exact string match
> (-F) and the string must be the entire line (-x).
>
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>   lfs/Config | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lfs/Config b/lfs/Config
> index 1a59ebe1e..8547f69c6 100644
> --- a/lfs/Config
> +++ b/lfs/Config
> @@ -292,13 +292,13 @@ define POSTBUILD
>   		fi; \
>   		sed -e "s/BUILDTARGET/$(BUILDTARGET)/g" -e "s/KVER/$(KVER)/g" -e "s/xxxMACHINExxx/$(BUILD_ARCH)/g" $$ROOTFILE > $(TARGET)_rootfile; \
>   		while read -r line; do \
> -			if grep -qG "^#$$line$$" $(TARGET)_rootfile; then echo "#$$line" >> $(TARGET); \
> -			elif grep -qG "^$$line$$" $(TARGET)_rootfile ; then echo "$$line" >> $(TARGET); \
> +			if grep -qFx "#$$line" $(TARGET)_rootfile; then echo "#$$line" >> $(TARGET); \
> +			elif grep -qFx "$$line" $(TARGET)_rootfile ; then echo "$$line" >> $(TARGET); \
>   			else echo "+$$line" >> $(TARGET); \
>   			fi; \
>   		done < $(TARGET)_diff; \
>   		grep -v "^#" $(TARGET)_rootfile | while read -r line; do \
> -			if ! grep -qG "^$$line$$" $(TARGET)_diff ; then echo "-$$line" >> $(TARGET); \
> +			if ! grep -qFx "$$line" $(TARGET)_diff ; then echo "-$$line" >> $(TARGET); \
>   			fi; \
>   		done; \
>   		rm -f $(TARGET)_rootfile; \
  

Patch

diff --git a/lfs/Config b/lfs/Config
index 1a59ebe1e..8547f69c6 100644
--- a/lfs/Config
+++ b/lfs/Config
@@ -292,13 +292,13 @@  define POSTBUILD
 		fi; \
 		sed -e "s/BUILDTARGET/$(BUILDTARGET)/g" -e "s/KVER/$(KVER)/g" -e "s/xxxMACHINExxx/$(BUILD_ARCH)/g" $$ROOTFILE > $(TARGET)_rootfile; \
 		while read -r line; do \
-			if grep -qG "^#$$line$$" $(TARGET)_rootfile; then echo "#$$line" >> $(TARGET); \
-			elif grep -qG "^$$line$$" $(TARGET)_rootfile ; then echo "$$line" >> $(TARGET); \
+			if grep -qFx "#$$line" $(TARGET)_rootfile; then echo "#$$line" >> $(TARGET); \
+			elif grep -qFx "$$line" $(TARGET)_rootfile ; then echo "$$line" >> $(TARGET); \
 			else echo "+$$line" >> $(TARGET); \
 			fi; \
 		done < $(TARGET)_diff; \
 		grep -v "^#" $(TARGET)_rootfile | while read -r line; do \
-			if ! grep -qG "^$$line$$" $(TARGET)_diff ; then echo "-$$line" >> $(TARGET); \
+			if ! grep -qFx "$$line" $(TARGET)_diff ; then echo "-$$line" >> $(TARGET); \
 			fi; \
 		done; \
 		rm -f $(TARGET)_rootfile; \