Package: debianutils
Version: 2.11.2
Severity: normal
File: /usr/bin/savelog
Tags: patch


savelog itself doesn't choke on the hyphen;  it just fails to protect
against the hyphen for the programs it calls, so you get:

% echo foo > -c
% ls -l -- -c*
-rw-------  1 sundell users 4 Feb 12 16:46 -c
% savelog -- -c
mv: invalid option -- c
Try `mv --help' for more information.
Rotated `-c' at Sat Feb 12 16:46:58 PST 2005.
% ls -l -- -c*
-rw-------  1 sundell users 4 Feb 12 16:46 -c
-rw-------  1 sundell users 0 Feb 12 16:46 -c.0

The attached patch fixes the problem in my testing.


-- System Information:
Debian Release: 3.1
Architecture: i386 (i686)
Kernel: Linux 2.6.10-grsec
Locale: LANG=C, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages debianutils depends on:
ii  coreutils                   5.2.1-2      The GNU core utilities
ii  libc6                       2.3.2.ds1-20 GNU C Library: Shared libraries an

-- no debconf information
--- /usr/bin/savelog    2004-12-24 12:36:31.000000000 -0800
+++ /tmp/savelog        2005-02-12 16:30:41.000000000 -0800
@@ -120,13 +120,13 @@
 fixfile()
 {
     if [ -n "$user" ]; then
-       chown "$user" "$1"
+       chown -- "$user" "$1"
     fi
     if [ -n "$group" ]; then 
-       chgrp "$group" "$1"
+       chgrp -- "$group" "$1"
     fi
     if [ -n "$mode" ]; then 
-       chmod "$mode" "$1"
+       chmod -- "$mode" "$1"
     fi
 }
 
@@ -177,7 +177,7 @@
        if [ ! -s $filename ] && [ "$rotateifempty" != "yes" ]; then
                # if -t was given and it does not exist, create it
                if test -n "$touch" && [ ! -f "$filename" ]; then 
-                       touch "$filename"
+                       touch -- "$filename"
                        if [ "$?" -ne 0 ]; then
                                echo "$prog: could not touch $filename" 1>&2
                                exitcode=4
@@ -190,19 +190,19 @@
 
        # be sure that the savedir exists and is writable
        # (Debian default: $savedir is . and not ./OLD)
-       savedir=`dirname "$filename"`
+       savedir=`dirname -- "$filename"`
        if [ -z "$savedir" ]; then
                savedir=.
        fi
        savedir="$savedir/$rolldir"
        if [ ! -d "$savedir" ]; then
-               mkdir -p "$savedir"
+               mkdir -p -- "$savedir"
                if [ "$?" -ne 0 ]; then
                        echo "$prog: could not mkdir $savedir" 1>&2
                        exitcode=5
                        continue
                fi
-               chmod 0755 "$savedir"
+               chmod 0755 -- "$savedir"
        fi
        if [ ! -w "$savedir" ]; then
                echo "$prog: directory $savedir is not writable" 1>&2
@@ -211,24 +211,24 @@
        fi
  
        # determine our uncompressed file names
-       newname=`basename "$filename"`
+       newname=`basename -- "$filename"`
        newname="$savedir/$newname"
 
        # cycle the old compressed log files
        cycle=$(( $count - 1))
-       rm -f "$newname.$cycle" "$newname.$cycle$DOT_Z"
+       rm -f -- "$newname.$cycle" "$newname.$cycle$DOT_Z"
        while [ $cycle -gt 1 ]; do
                # --cycle
                oldcycle=$cycle
                cycle=$(( $cycle - 1 ))
                # cycle log
                if [ -f "$newname.$cycle$DOT_Z" ]; then
-                       mv -f "$newname.$cycle$DOT_Z" \
+                       mv -f -- "$newname.$cycle$DOT_Z" \
                            "$newname.$oldcycle$DOT_Z"
                fi
                if [ -f "$newname.$cycle" ]; then
                        # file was not compressed. move it anyway
-                       mv -f "$newname.$cycle" "$newname.$oldcycle"
+                       mv -f -- "$newname.$cycle" "$newname.$oldcycle"
                fi
        done
 
@@ -236,41 +236,41 @@
        if [ -f "$newname.0" ]; then
                if [ -z "$COMPRESS" ]; then
                        newfile="$newname.1"
-                       mv "$newname.0" "$newfile"
+                       mv -- "$newname.0" "$newfile"
                else
                        newfile="$newname.1$DOT_Z"
 #                      $COMPRESS < $newname.0 > $newfile
 #                      rm -f $newname.0
                        $COMPRESS "$newname.0"
-                       mv "$newname.0$DOT_Z" "$newfile"
+                       mv -- "$newname.0$DOT_Z" "$newfile"
                fi
                fixfile "$newfile"
        fi
 
        # compress the old uncompressed log if needed
        if test -n "$datum" && test -n "$COMPRESS"; then
-               $COMPRESS $newname.[0-9]*[0-9]
+               $COMPRESS -- $newname.[0-9]*[0-9]
        fi
 
        # remove old files if so desired
        if [ -n "$forceclean" ]; then
                cycle=$(( $count - 1))
                if [ -z "$COMPRESS" ]; then
-                       rm -f `ls -t $newname.[0-9]* | sed -e 1,${cycle}d`
+                       rm -f -- `ls -t -- $newname.[0-9]* | sed -e 1,${cycle}d`
                else
-                       rm -f `ls -t $newname.[0-9]*$DOT_Z | sed -e 1,${cycle}d`
+                       rm -f -- `ls -t -- $newname.[0-9]*$DOT_Z | sed -e 
1,${cycle}d`
                fi
        fi
 
        # create new file if needed
        if [ -n "$preserve" ]; then
                (umask 077
-                touch "$filename.new"
-                chown --reference "$filename" "$filename.new"
-                chmod --reference "$filename" "$filename.new")
+                touch -- "$filename.new"
+                chown --reference -- "$filename" "$filename.new"
+                chmod --reference -- "$filename" "$filename.new")
                filenew=1
        elif [ -n "$touch$user$group$mode" ]; then
-               touch "$filename.new"
+               touch -- "$filename.new"
                fixfile "$filename.new"
                filenew=1
        fi
@@ -278,21 +278,21 @@
        # link the file into the file.0 holding place
        if [ -f "$filename" ]; then
                if [ -n "$filenew" ]; then
-                       if ln -f "$filename" "$newname.0"; then
-                               mv "$filename.new" "$filename"
+                       if ln -f -- "$filename" "$newname.0"; then
+                               mv -- "$filename.new" "$filename"
                        else
                                echo "Error hardlinking $filename to 
$newname.0" >&2
                                exitcode=8
                                continue
                        fi
                else
-                       mv "$filename" "$newname.0"
+                       mv -- "$filename" "$newname.0"
                fi
        fi
-       [ ! -f "$newname.0" ] && touch "$newname.0"
+       [ ! -f "$newname.0" ] && touch -- "$newname.0"
        fixfile "$newname.0"
        if [ -n "$datum" ]; then
-               mv $newname.0 $newname.$DATUM
+               mv -- $newname.0 $newname.$DATUM
        fi
 
        # report successful rotation

Reply via email to