[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bad init.d scripts



I have noticed a pattern of bugs in /etc/init.d scripts, in
regular expressions.  It appears that we all understand
RE's so well that we are not checking that they are actually
right.  For example, in diald 0.16.5-3 /etc/init.d/diald, we 
(still!) have 

  NEW_FIFO=`egrep '^[^#]*fifo' /etc/diald/diald.options | 
    sed -e 's/^ *fifo *//'`

Now, this isn't as bad as it might be because there are no
"foofifo" keywords defined for the option file, _yet_.
(Though the effect of a leading tab is silent confusion.)
But why is grep applying a different pattern than sed?  
(Why, anyway, is this using egrep (and not grep) at all?  
It's not using any egrep extensions.)  In fact, 
egrep is looking for the wrong pattern.  This should really be

  NEW_FIFO=`egrep '^ *fifo ' /etc/diald/diald.options | 
    sed -e 's/^ *fifo *//'`

or better, a single sed command.

It should be ignoring comments, but should not be matching 
every line (including comment lines!) whose first word happens to end 
in "fifo".

Similarly, in apache 1.3.3-4, we have /etc/init.d/apache:

  if egrep -i "[^#]*\<ServerType\> inet" $CONF > /dev/null

This is really bad.  It means that if there is a line

  #ServerType inetd

the egrep will find it, despite that it appears to be trying not to.

The common theme is that these patterns should not have this junk
("[^#]") at the front to try to avoid comment lines; they should 
instead just be looking for the lines they want.  Further, 
they probably should permit mixed TAB and space characters 
at the beginning of the line:
  
  white='	 ' # tab and space
  egrep "^[$white]*foo\>" ...

I have not done a thorough audit, and do not have all packages
installed (as if that were possible :-), but it seems worthwhile 
to look through the init.d files for all packages that use them
and check that they are in fact correct.  It seems likely that any 
script which uses the pattern "[^#]*" in a RE is broken, but there 
are undoubtedly other broken REs in use as well.

A broken Apache installation is likely to be an embarrassment to 
Debian. 

Nathan Myers
ncm@cantrip.org
p.s.  No, I have not filed a bug report against apache or diald.


Reply to: