Bug#691422: init-functions: order of arguments is not context-free

Jeff Licquia <[email protected]>
Newsgroups gmane.linux.debian.devel.lsb
Message-ID <[email protected]>
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".
0001-Sanity-check-pidofproc-parameters-per-Debian-bug-691.patch (text/x-patch, 1.5 KB)
>From 5772eb3bfb45ea3de2f0e06bb4f3dd3eeafccdf6 Mon Sep 17 00:00:00 2001
From: Jeff Licquia <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.