buildscript: check selected_bsp link target

Submitted by Adrian Schmutzler on April 17, 2020, 12:21 p.m.

Details

Message ID 20200417122113.1458-1-freifunk@adrianschmutzler.de
State Accepted
Headers show

Commit Message

Adrian Schmutzler April 17, 2020, 12:21 p.m.
While buildscript checks whether selected_bsp exists, it does not
verify whether it is pointing to a sensible direction.

Since we use the target file name and content to derive build folders
etc., though, this patch adds a check and exits the script if the
link is broken.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 buildscript | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/buildscript b/buildscript
index d2da0e30..9f6217c2 100755
--- a/buildscript
+++ b/buildscript
@@ -360,7 +360,14 @@  clean() {
 
 loadBSP()
 {
-    echo "Working with $(/bin/ls -l selected_bsp | awk '{ print $11 }')"
+    localbsppath=$(/bin/ls -l selected_bsp | awk '{ print $11 }')
+
+    if ! [ -s selected_bsp ]; then
+        echo "Error: $localbsppath does not exist. Aborting ..."
+        exit 1
+    fi
+
+    echo "Working with $localbsppath"
     . selected_bsp
     machine=$(basename $(realpath selected_bsp) .bsp)
 }

Comments

Fabian Blaese April 17, 2020, 2:27 p.m.
Reviewed-by: Fabian Bläse <fabian@blaese.de>

On 17.04.20 14:21, Adrian Schmutzler wrote:
> While buildscript checks whether selected_bsp exists, it does not
> verify whether it is pointing to a sensible direction.
> 
> Since we use the target file name and content to derive build folders
> etc., though, this patch adds a check and exits the script if the
> link is broken.
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>  buildscript | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/buildscript b/buildscript
> index d2da0e30..9f6217c2 100755
> --- a/buildscript
> +++ b/buildscript
> @@ -360,7 +360,14 @@ clean() {
>  
>  loadBSP()
>  {
> -    echo "Working with $(/bin/ls -l selected_bsp | awk '{ print $11 }')"
> +    localbsppath=$(/bin/ls -l selected_bsp | awk '{ print $11 }')
> +
> +    if ! [ -s selected_bsp ]; then
> +        echo "Error: $localbsppath does not exist. Aborting ..."
> +        exit 1
> +    fi
> +
> +    echo "Working with $localbsppath"
>      . selected_bsp
>      machine=$(basename $(realpath selected_bsp) .bsp)
>  }
>
Fabian Blaese April 17, 2020, 3:08 p.m.
applied.