From 25d68e6c5b601ba3eb5f6425d3576a54d2a846ab Mon Sep 17 00:00:00 2001 From: Chris Maynard Date: Mon, 14 Feb 2011 01:44:15 +0000 Subject: Disallow invalid char's in the filename passed to idl2wrs. Fixes bug 1129. svn path=/trunk/; revision=35944 --- doc/README.idl2wrs | 4 ++-- docbook/wsug_src/WSUG_app_tools.xml | 2 +- tools/idl2wrs.sh.in | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/README.idl2wrs b/doc/README.idl2wrs index 974356d011..dae1f2a416 100644 --- a/doc/README.idl2wrs +++ b/doc/README.idl2wrs @@ -63,7 +63,7 @@ Procedure 1. To write the C code to stdout. - idl2wrs + idl2wrs eg: idl2wrs echo.idl @@ -81,7 +81,7 @@ steps 3 or 4 instead. 3. To write the C code to stdout. - Usage: omniidl -p ./ -b wireshark_be + Usage: omniidl -p ./ -b wireshark_be eg: omniidl -p ./ -b wireshark_be echo.idl diff --git a/docbook/wsug_src/WSUG_app_tools.xml b/docbook/wsug_src/WSUG_app_tools.xml index 3aae21569a..7f8f30ded5 100644 --- a/docbook/wsug_src/WSUG_app_tools.xml +++ b/docbook/wsug_src/WSUG_app_tools.xml @@ -941,7 +941,7 @@ Miscellaneous: To write the C code to stdout. - idl2wrs <your file.idl> + idl2wrs <your_file.idl> e.g.: idl2wrs echo.idl diff --git a/tools/idl2wrs.sh.in b/tools/idl2wrs.sh.in index 9fa33ba0be..ec3a4cfa4c 100644 --- a/tools/idl2wrs.sh.in +++ b/tools/idl2wrs.sh.in @@ -48,6 +48,25 @@ if [ $# -lt 1 ]; then exit 1; fi +# Check the file name for valid characters. +# Implementation based on Dave Taylor's validalnum shell script from his book, +# "Wicked Cool Shell Scripts", as well as Mark Rushakoff's answer he provided +# to the question posted at stackoverflow.com entitled, "How can I use the +# UNIX shell to count the number of times a letter appears in a text file?" +file=$(basename $1) +compressed="$(echo $file | sed 's/[^[:alnum:]._]//g')" +if [ "$compressed" != "$file" ]; then + echo "idl2wrs Error: Invalid file name: $file" + exit 1; +fi + +# Only allow one '.' at most. +count=$(echo $compressed | awk -F. '{c += NF - 1} END {print c}') +if [ $count -gt 1 ] ; then + echo "idl2wrs Error: Invalid file name: $file" + exit 1; +fi + # # Run wireshark backend, looking for wireshark_be.py and wireshark_gen.py # in pythons's "site-packages" directory. If cannot find that, then -- cgit v1.2.3