[v1] usertools/dpdk-setup.sh: fix dpdk-setup's behaviour on non-alphanumeric inputs

Message ID 20200319174423.28378-1-sarosh.arif@emumba.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series [v1] usertools/dpdk-setup.sh: fix dpdk-setup's behaviour on non-alphanumeric inputs |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK

Commit Message

Sarosh Arif March 19, 2020, 5:44 p.m. UTC
  Bugzilla ID: 419
Cc: stable@dpdk.org
Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
---
 usertools/dpdk-setup.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger March 19, 2020, 6:20 p.m. UTC | #1
On Thu, 19 Mar 2020 22:44:23 +0500
Sarosh Arif <sarosh.arif@emumba.com> wrote:

> Bugzilla ID: 419
> Cc: stable@dpdk.org
> Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
> ---
>  usertools/dpdk-setup.sh | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
> index e5bbe9fee..bdacf5256 100755
> --- a/usertools/dpdk-setup.sh
> +++ b/usertools/dpdk-setup.sh
> @@ -595,8 +595,14 @@ while [ "$QUIT" == "0" ]; do
>  	echo -n "Option: "
>  	read our_entry
>  	echo ""
> -	${OPTIONS[our_entry]} ${our_entry}
> -
> +	echo $our_entry | grep "^[0-9]*$" > /dev/null
> +
> +	if  [ "$?" -eq 0 ] ; then
> +		${OPTIONS[our_entry]} ${our_entry}
> +	else
> +		echo "Wrong input format"
> +	fi
> +
>  	if [ "$QUIT" == "0" ] ; then
>  		echo
>  		echo -n "Press enter to continue ..."; read


Why not do it with regex (abi check has similar code) and
use the nice format.

Also handle EOF

diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
index e5bbe9feec49..f594769a4ef1 100755
--- a/usertools/dpdk-setup.sh
+++ b/usertools/dpdk-setup.sh
@@ -592,10 +592,16 @@ while [ "$QUIT" == "0" ]; do
        echo "[$OPTION_NUM] Exit Script"
        OPTIONS[$OPTION_NUM]="quit"
        echo ""
-       echo -n "Option: "
-       read our_entry
+       read -p "Option: " our_entry
+       [ $? -eq 0 ] || exit 0
+
        echo ""
-       ${OPTIONS[our_entry]} ${our_entry}
+       numeric="^[[:digit:]]+$"
+       if [[ "$our_entry" =~ $numeric ]]; then
+               ${OPTIONS[our_entry]} ${our_entry}
+       else
+               echo "Please enter a numeric value"
+       fi

        if [ "$QUIT" == "0" ] ; then
                echo
--
  

Patch

diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
index e5bbe9fee..bdacf5256 100755
--- a/usertools/dpdk-setup.sh
+++ b/usertools/dpdk-setup.sh
@@ -595,8 +595,14 @@  while [ "$QUIT" == "0" ]; do
 	echo -n "Option: "
 	read our_entry
 	echo ""
-	${OPTIONS[our_entry]} ${our_entry}
-
+	echo $our_entry | grep "^[0-9]*$" > /dev/null
+
+	if  [ "$?" -eq 0 ] ; then
+		${OPTIONS[our_entry]} ${our_entry}
+	else
+		echo "Wrong input format"
+	fi
+
 	if [ "$QUIT" == "0" ] ; then
 		echo
 		echo -n "Press enter to continue ..."; read