Bug#795954: sysconfig-hardware contains various syntax errors in "case" commands
On Tue, Aug 18, 2015 at 06:07:57AM -0400, Stephen Powell wrote: > The sysconfig-hardware package contains a number of syntax errors in "case" > commands. The "case" command requires that after each pattern specification > there must be a command list, and this command list must be terminated by > a double semicolon. This is incorrect if you look at POSIX: The compound-list for each list of patterns, with the possible exception of the last, shall be terminated with ";;". http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html "Case Conditional Construct" > In some places, the only thing between the end of the pattern > specification and the double semicolon is a comment. A comment is not > a list. A null command (a colon) will do, but there must be at least > one command present to constitute a list. In other places, there is > no double semicolon to terminate the list. This also is a violation > of the rules of valid syntax. Well, all of the scripts declare that they are run with bash. It's clearer to pass in the : built-in and I couldn't find language lawyering that would allow the empty compound-list here at first glance, but it's also highly unlikely that bash will change in a fashion that forbids this. To improve correctness it makes sense to apply the patch. Kind regards Philipp Kern signature.asc Description: Digital signature
Bug#795954: sysconfig-hardware contains various syntax errors in "case" commands
On Sat, 05 Sep 2015 13:51:22 -0400 (EDT), Philipp Kern wrote: > > This is incorrect if you look at POSIX: > > The compound-list for each list of patterns, with the possible exception > of the last, shall be terminated with ";;". > > http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html > "Case Conditional Construct" I wasn't looking at POSIX, I was looking at "man bash". bash supports two alternate delimiters to ";;", namely, ";&", and ";;&", but use of these delimiters alters subsequent behavior. I could find nowhere in the documentation for the case command in "man bash" which stated that the delimiter could be eliminated entirely under any conditions. Note that the two alternate delimiters I mentioned are *not* POSIX compliant. > > Well, all of the scripts declare that they are run with bash. It's > clearer to pass in the : built-in and I couldn't find language lawyering > that would allow the empty compound-list here at first glance, but it's > also highly unlikely that bash will change in a fashion that forbids > this. Again, "man bash" states: "A list is a sequence of one or more pipelines ..." Notice that the definition says "one or more pipelines", not "zero or more pipelines". Interestingly enough, "man dash" *does* say "zero or more pipelines". But sysconfig-hardware requires bash. I tried once to convert it to dash, but ran into problems with array assignment statements that I didn't know how to convert, and decided to leave well enough alone. > > To improve correctness it makes sense to apply the patch. I agree. -- .''`. Stephen Powell: :' : `. `'` `-
Bug#795954: sysconfig-hardware contains various syntax errors in case commands
Package: sysconfig-hardware Version: 0.0.10+nmu1 Severity: minor Tags: patch X-Debbugs-CC: debian-s...@lists.debian.org The sysconfig-hardware package contains a number of syntax errors in case commands. The case command requires that after each pattern specification there must be a command list, and this command list must be terminated by a double semicolon. This is violated in several places. In some places, the only thing between the end of the pattern specification and the double semicolon is a comment. A comment is not a list. A null command (a colon) will do, but there must be at least one command present to constitute a list. In other places, there is no double semicolon to terminate the list. This also is a violation of the rules of valid syntax. For some reason, the code has apparently been executing more or less correctly; but a future release of bash (yes, bash, not dash) may tighten up standards and the code will fail. I have attached a patch file which corrects the problems. Note: the portion of the patch which changes chandev-convert affects only the source package. It is not included in the binary package. -- .''`. Stephen Powellzlinux...@wowway.com : :' : `. `'` `-diff -uar a/etc/sysconfig/scripts/hardware/functions b/etc/sysconfig/scripts/hardware/functions --- a/etc/sysconfig/scripts/hardware/functions 2010-10-30 10:50:49.0 -0400 +++ b/etc/sysconfig/scripts/hardware/functions 2015-08-18 05:36:06.411307488 -0400 @@ -27,6 +27,7 @@ echo $SCRIPTNAME: illegal option -- $OPTARG 2 echo Try: \`$SCRIPTNAME -h' for mor information. 2 exit $R_USAGE + ;; esac done diff -uar a/etc/sysconfig/scripts/hardware/hwup b/etc/sysconfig/scripts/hardware/hwup --- a/etc/sysconfig/scripts/hardware/hwup 2010-10-30 10:28:43.0 -0400 +++ b/etc/sysconfig/scripts/hardware/hwup 2015-08-18 05:38:22.536360188 -0400 @@ -17,6 +17,7 @@ case ${STARTMODE:-auto}:$MODE in auto:auto|*:auto-override) # Start auto devices in auto and override mode. + : ;; *:auto) # Don't display any message if device is not auto in auto mode. @@ -24,6 +25,7 @@ ;; auto:manual|manual:manual) # Start manual devices in manual mode. + : ;; off:manual) message $SCRIPTNAME: used configuration has STARTMODE=$STARTMODE. @@ -32,6 +34,7 @@ *) message $SCRIPTNAME: unknown STARTMODE=$STARTMODE. exit $R_ERROR + ;; esac source $SYSCONFIG/scripts/hardware/$COMMAND-$BUS $ID $DEVPATH diff -uar a/usr/share/sysconfig/chandev-convert b/usr/share/sysconfig/chandev-convert --- a/usr/share/sysconfig/chandev-convert 2009-03-24 06:10:51.0 -0400 +++ b/usr/share/sysconfig/chandev-convert 2015-08-18 05:40:58.760978505 -0400 @@ -26,6 +26,7 @@ echo $SCRIPTNAME: illegal option -- $OPTARG 2 echo Try: \`$SCRIPTNAME -h' for mor information. 2 exit $R_USAGE +;; esac done