Bug#691422: init-functions: order of arguments is not context-free
On 11/04/2012 12:02 PM, Arno Töll wrote:
> That said, I can live with you not wanting to fix it, but please give an
> error message at least, if you got an unexpected keyword argument after
> a positional if you do not intend to support it:
I've attached a patch which will add some sanity checking to pidofproc's
command-line argument parsing. With this patch, pidofproc will fail if
it finds more than one non-dashed argument under any circumstances.
I've also created a simple test.
I'll leave it up to Didier as to whether to apply it or just leave the
bug "wontfix".
>From 5772eb3bfb45ea3de2f0e06bb4f3dd3eeafccdf6 Mon Sep 17 00:00:00 2001
From: Jeff Licquia <licquia@debian.org>
Date: Sat, 10 Nov 2012 10:26:30 -0500
Subject: [PATCH] Sanity-check pidofproc parameters per Debian bug 691422.
---
init-functions | 4 ++++
test/lsb-test.sh | 28 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/init-functions b/init-functions
index 5cb28dc..046dfb9 100644
--- a/init-functions
+++ b/init-functions
@@ -75,6 +75,10 @@ pidofproc () {
esac
done
shift $(($OPTIND - 1))
+ if [ $# -ne 1 ]; then
+ echo "$0: invalid arguments" >&2
+ return 4
+ fi
base=${1##*/}
if [ ! "$specified" ]; then
diff --git a/test/lsb-test.sh b/test/lsb-test.sh
index 1168a62..2db3457 100644
--- a/test/lsb-test.sh
+++ b/test/lsb-test.sh
@@ -8,3 +8,31 @@ log_success_msg "This should succeed"
log_failure_msg "This fails miserably"
echo "OK!"
+
+# Test pidofproc sanity checking.
+
+echo "Testing pidofproc command line checks"
+
+echo " Simple check, no options:"
+pidofproc nonexistent
+RETVAL=$?
+if [ $RETVAL -ne 3 ]; then
+ echo "Unexpected return value $RETVAL"
+fi
+
+echo " With -p option:"
+pidofproc -p /var/run/nonexist.pid nonexistent
+RETVAL=$?
+if [ $RETVAL -ne 3 ]; then
+ echo "Unexpected return value $RETVAL"
+fi
+
+echo " With -p option, but in wrong place:"
+pidofproc nonexistent -p /var/run/nonexist.pid
+RETVAL=$?
+if [ $RETVAL -ne 4 ]; then
+ echo "Unexpected return value $RETVAL"
+fi
+
+echo "OK!"
+
--
1.7.10.4
Reply to: