]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
buildtools-tarball: fix unbound variable issues under 'set -u'
authorHaixiao Yan <haixiao.yan.cn@windriver.com>
Fri, 12 Sep 2025 01:59:33 +0000 (09:59 +0800)
committerSteve Sakoman <steve@sakoman.com>
Wed, 17 Sep 2025 16:51:15 +0000 (09:51 -0700)
When Bash runs with 'set -u' (nounset), accessing an unset variable
directly (e.g. [ -z "$SSL_CERT_FILE" ]) causes a fatal "unbound variable"
error. As a result, the fallback logic to set SSL_CERT_FILE/SSL_CERT_DIR
is never triggered and the script aborts.

The current code assumes these variables may be unset or empty, but does
not guard against 'set -u'. This breaks builds in stricter shell
environments or when users explicitly enable 'set -u'.

Fix this by using parameter expansion with a default value, e.g.
"${SSL_CERT_FILE:-}", so that unset variables are treated as empty
strings. This preserves the intended logic (respect host env first, then
CAFILE/CAPATH, then buildtools defaults) and makes the script robust
under 'set -u'.

Signed-off-by: Haixiao Yan <haixiao.yan.cn@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 4d880c2eccd534133a2a4e6579d955605c0956ec)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
meta/recipes-connectivity/openssl/files/environment.d-openssl.sh
meta/recipes-devtools/git/git/environment.d-git.sh
meta/recipes-devtools/python/python3-requests/environment.d-python3-requests.sh
meta/recipes-support/curl/curl/environment.d-curl.sh

index 71d378734c2d3965c28194896a269c7f8833e716..0e75e34f9d924a52a72d7f2e8e61ed78a1fe078b 100644 (file)
@@ -5,16 +5,16 @@ export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} OPENSSL_C
 
 # Respect host env SSL_CERT_FILE/SSL_CERT_DIR first, then auto-detected host cert, then cert in buildtools
 # CAFILE/CAPATH is auto-deteced when source buildtools
-if [ -z "$SSL_CERT_FILE" ]; then
-       if [ -n "$CAFILE" ];then
+if [ -z "${SSL_CERT_FILE:-}" ]; then
+       if [ -n "${CAFILE:-}" ];then
                export SSL_CERT_FILE="$CAFILE"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export SSL_CERT_FILE="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/certs/ca-certificates.crt"
        fi
 fi
 
-if [ -z "$SSL_CERT_DIR" ]; then
-       if [ -n "$CAPATH" ];then
+if [ -z "${SSL_CERT_DIR:-}" ]; then
+       if [ -n "${CAPATH:-}" ];then
                export SSL_CERT_DIR="$CAPATH"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export SSL_CERT_DIR="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/certs"
index 9c7b5a92512ad025bfc65aea58fe0cd4dbcdabdd..fdfa721c3b2ed7988a6fac01936c35eb7e6b95f3 100644 (file)
@@ -1,15 +1,15 @@
 # Respect host env GIT_SSL_CAINFO/GIT_SSL_CAPATH first, then auto-detected host cert, then cert in buildtools
 # CAFILE/CAPATH is auto-deteced when source buildtools
-if [ -z "$GIT_SSL_CAINFO" ]; then
-       if [ -n "$CAFILE" ];then
+if [ -z "${GIT_SSL_CAINFO:-}" ]; then
+       if [ -n "${CAFILE:-}" ];then
                export GIT_SSL_CAINFO="$CAFILE"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export GIT_SSL_CAINFO="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt"
        fi
 fi
 
-if [ -z "$GIT_SSL_CAPATH" ]; then
-       if [ -n "$CAPATH" ];then
+if [ -z "${GIT_SSL_CAPATH:-}" ]; then
+       if [ -n "${CAPATH:-}" ];then
                export GIT_SSL_CAPATH="$CAPATH"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export GIT_SSL_CAPATH="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs"
index 492177a9c377f56636235e77a6c6e7cefdb97e63..400972814b6ed237df29919fee4cb74cf77eea8c 100644 (file)
@@ -1,7 +1,7 @@
 # Respect host env REQUESTS_CA_BUNDLE first, then auto-detected host cert, then cert in buildtools
 # CAFILE/CAPATH is auto-deteced when source buildtools
-if [ -z "$REQUESTS_CA_BUNDLE" ]; then
-       if [ -n "$CAFILE" ];then
+if [ -z "${REQUESTS_CA_BUNDLE:-}" ]; then
+       if [ -n "${CAFILE:-}" ];then
                export REQUESTS_CA_BUNDLE="$CAFILE"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export REQUESTS_CA_BUNDLE="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt"
index 7c2971b3dad1e405880809f33c67a9d56ec929ed..581108ef35d8660fa2cb505ca647c01c536d8f73 100644 (file)
@@ -1,15 +1,15 @@
 # Respect host env CURL_CA_BUNDLE/CURL_CA_PATH first, then auto-detected host cert, then cert in buildtools
 # CAFILE/CAPATH is auto-deteced when source buildtools
-if [ -z "$CURL_CA_PATH" ]; then
-       if [ -n "$CAFILE" ];then
+if [ -z "${CURL_CA_PATH:-}" ]; then
+       if [ -n "${CAFILE:-}" ];then
                export CURL_CA_BUNDLE="$CAFILE"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export CURL_CA_BUNDLE="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt"
        fi
 fi
 
-if [ -z "$CURL_CA_PATH" ]; then
-       if [ -n "$CAPATH" ];then
+if [ -z "${CURL_CA_PATH:-}" ]; then
+       if [ -n "${CAPATH:-}" ];then
                export CURL_CA_PATH="$CAPATH"
        elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then
                export CURL_CA_PATH="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs"