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

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

Checks

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

Commit Message

Sarosh Arif March 19, 2020, 1:31 p.m. UTC
  Used regular expression to see if the input is numeric, otherwise prompts the user to re-enter.

Bugzilla ID: 419
Cc: stable@dpdk.org

Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
---
 usertools/dpdk-setup.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
 mode change 100755 => 100644 usertools/dpdk-setup.sh
  

Comments

Stephen Hemminger March 19, 2020, 3:17 p.m. UTC | #1
On Thu, 19 Mar 2020 18:31:47 +0500
Sarosh Arif <sarosh.arif@emumba.com> wrote:

> -	${OPTIONS[our_entry]} ${our_entry}
>  
> +	re='^[0-9]+$'
> +	if  [[ $our_entry =~ $re ]] ; then
> +	${OPTIONS[our_entry]} ${our_entry}
> +	fi
> +

Some comments:
1. Use same indentation style as the rest of the script
   This follows the mantra that all repairs should like
   the original code.
2. If user gives bad data, an error should be printed
   and not silently ignored.
3.The variable "re" doesn't need to be a temporary variable.

4. The [[ construct is a bash only thing, and not used elsewhere
   in the script.
  

Patch

diff --git a/usertools/dpdk-setup.sh b/usertools/dpdk-setup.sh
old mode 100755
new mode 100644
index e5bbe9fee..a29fdc677
--- a/usertools/dpdk-setup.sh
+++ b/usertools/dpdk-setup.sh
@@ -595,8 +595,12 @@  while [ "$QUIT" == "0" ]; do
 	echo -n "Option: "
 	read our_entry
 	echo ""
-	${OPTIONS[our_entry]} ${our_entry}
 
+	re='^[0-9]+$'
+	if  [[ $our_entry =~ $re ]] ; then
+	${OPTIONS[our_entry]} ${our_entry}
+	fi
+
 	if [ "$QUIT" == "0" ] ; then
 		echo
 		echo -n "Press enter to continue ..."; read