Blob Blame History Raw
From cef782ca658d695c5ca2d174ba1f89cba6bd84e5 Mon Sep 17 00:00:00 2001
Message-Id: <cef782ca658d695c5ca2d174ba1f89cba6bd84e5.1637749821.git.aclaudi@redhat.com>
From: Andrea Claudi <aclaudi@redhat.com>
Date: Wed, 24 Nov 2021 11:28:08 +0100
Subject: [PATCH] configure: fix parsing issue on include_dir option

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2009355
Upstream Status: iproute2.git commit 1d819dcc

commit 1d819dcc741e25958190e31f8186c940713fa0a8
Author: Andrea Claudi <aclaudi@redhat.com>
Date:   Thu Oct 14 10:50:49 2021 +0200

    configure: fix parsing issue on include_dir option

    configure is stuck in an endless loop if '--include_dir' option is used
    without a value:

    $ ./configure --include_dir
    ./configure: line 506: shift: 2: shift count out of range
    ./configure: line 506: shift: 2: shift count out of range
    [...]

    Fix it splitting 'shift 2' into two consecutive shifts, and making the
    second one conditional to the number of remaining arguments.

    A check is also provided after the while loop to verify the include dir
    exists; this avoid to produce an erroneous configuration.

    Fixes: a9c3d70d902a ("configure: add options ability")
    Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
    Acked-by: Phil Sutter <phil@nwl.cc>
    Signed-off-by: David Ahern <dsahern@kernel.org>
---
 configure | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 7f4f3bd9..ea9051ab 100755
--- a/configure
+++ b/configure
@@ -485,7 +485,7 @@ usage()
 {
 	cat <<EOF
 Usage: $0 [OPTIONS]
-	--include_dir		Path to iproute2 include dir
+	--include_dir <dir>	Path to iproute2 include dir
 	--libbpf_dir		Path to libbpf DESTDIR
 	--libbpf_force		Enable/disable libbpf by force. Available options:
 				  on: require link against libbpf, quit config if no libbpf support
@@ -502,8 +502,9 @@ else
 	while true; do
 		case "$1" in
 			--include_dir)
-				INCLUDE=$2
-				shift 2 ;;
+				shift
+				INCLUDE="$1"
+				[ "$#" -gt 0 ] && shift ;;
 			--libbpf_dir)
 				LIBBPF_DIR="$2"
 				shift 2 ;;
@@ -523,6 +524,8 @@ else
 	done
 fi
 
+[ -d "$INCLUDE" ] || usage 1
+
 echo "# Generated config based on" $INCLUDE >$CONFIG
 quiet_config >> $CONFIG
 
-- 
2.31.1