From: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Date: Tue, 8 Aug 2017 13:26:12 +0000 (+0200)
Subject: scripts: setlocalversion: safely extract variables from auto.conf using awk
X-Git-Tag: v2025.01-rc5-pxa1908~6047^2~4
X-Git-Url: http://git.dujemihanovic.xyz/%22http:/www.sics.se/static/%7B%7B%20%24.Site.BaseURL%20%7D%7Dposts/%7B%7B%20%24image.RelPermalink%20%7D%7D?a=commitdiff_plain;h=81630a3b38c22102dce3a15019db546af209344d;p=u-boot.git

scripts: setlocalversion: safely extract variables from auto.conf using awk

Moving SPL_LDSCRIPT to Kconfig triggered an unfortunate attempt of
command substitution, as the sourced auto.conf may include $(ARCH)
which tries to execute a command 'ARCH'.
This showed up as a warning similar to the following:
  include/config/auto.conf: line 209: ARCH: command not found

This change does no longer attempt to source auto.conf, but rather
passes it through awk to retrieve the values for CONFIG_LOCALVERSION
and CONFIG_LOCALVERSION_AUTO.  This will also mitigate the risk of
unintended command substitution.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Reported-by: Andy Yan <andy.yan@rock-chips.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Klaus Goger <klaus.goger@theobroma-systems.com>
Reviewed-by: Jakob Unterwurzacher <jakob.unterwurzacher@theobroma-systems.com>
---

diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 63d91e22ed..8564bedd1a 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -141,7 +141,11 @@ if $scm_only; then
 fi
 
 if test -e include/config/auto.conf; then
-	. include/config/auto.conf
+	# We are interested only in CONFIG_LOCALVERSION and
+        # CONFIG_LOCALVERSION_AUTO, so extract these in a safe
+        # way (i.e. w/o sourcing auto.conf)
+	CONFIG_LOCALVERSION=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION=/ {print $2}'`
+	CONFIG_LOCALVERSION_AUTO=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION_AUTO=/ {print $2}'`
 else
 	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
 	exit 1