Package: logrotate
Version: 3.8.7-1+b1

Logrotate fails to properly handle long filenames with long dateext 
dateformat, and crashes.

For this to happen, several conditions must be met simultaneously:
1. at least two files must need rotation
2. first filename must be between 7 and 33 characters long, or longer than 35
3. second filename must be either 34 or 35 characters long
4. compress must be enabled -- when delaycompress is in effect, bug does not
   appear
5. sharedscripts must be enabled (but a postrotate/prerotate script does not
   have to be defined)
6. dateext has to be enabled
7. dateformat has to be set to a string that:
   a). contains at least one specifier (%Y, %m, %d, or %s)
   b). with specifier(s) replaced by particular date string, the length of
       dateformat string has to be longer than 29 characters
8. olddir seems to be required, with olddir path (including path separators,
   e.g. '/tmp/old________logs') length at exactly 20 characters

I've been able to prepare a testcase script:
https://paste.debian.net/417413/

Tested on wheezy (in a docker container), jessie (both in a docker container 
and on bare metal), and stretch/sid (in a docker container). All seem to be 
affected. The script has to be run in /tmp or other three-letter directory.

Depending on circumstances (exact length of filenames, mainly), the result 
might be a segmentation error, invalid pointer, or 'free(): invalid next 
size'.

Obviously the correct behaviour would be for logrotate to properly handle the 
logs without dumping the core.

Example log:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

reading config file logrotate.conf
olddir is now /tmp/old________logs

Handling 1 logs

rotating pattern: /tmp/logs/*.log  forced from command line (no old logs will 
be kept)
olddir is /tmp/old________logs, empty log files are not rotated, old logs are 
removed
considering log /tmp/logs/ddddddddddddddd.log
  log needs rotating
considering log /tmp/logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log
  log needs rotating
rotating log /tmp/logs/ddddddddddddddd.log, log->rotateCount is 0
Converted ' -%Y.56789.xxxxxxxxxxxxxxxxx' -> '-%Y.56789.xxxxxxxxxxxxxxxxx'
dateext suffix '-2016.56789.xxxxxxxxxxxxxxxxx'
glob pattern '-[0-9][0-9][0-9][0-9].56789.xxxxxxxxxxxxxxxxx'
glob finding old rotated logs failed
rotating log /tmp/logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log, log->rotateCount 
is 0
Converted ' -%Y.56789.xxxxxxxxxxxxxxxxx' -> '-%Y.56789.xxxxxxxxxxxxxxxxx'
dateext suffix '-2016.56789.xxxxxxxxxxxxxxxxx'
glob pattern '-[0-9][0-9][0-9][0-9].56789.xxxxxxxxxxxxxxxxx'
glob finding old rotated logs failed
renaming /tmp/logs/ddddddddddddddd.log to 
/tmp/old________logs/ddddddddddddddd.log-2016.56789.xxxxxxxxxxxxxxxxx
disposeName will be 
/tmp/old________logs/ddddddddddddddd.log-2016.56789.xxxxxxxxxxxxxxxxx.gz
creating new /tmp/logs/ddddddddddddddd.log mode = 0644 uid = 0 gid = 0
renaming /tmp/logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log to 
/tmp/old________logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log-2016.56789.xxxxxxxxxxxxxxxxx
disposeName will be 
/tmp/old________logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log-2016.56789.xxxxxxxxxxxxxxxxx.gz
creating new /tmp/logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log mode = 0644 uid = 0 
gid = 0
compressing log with: /bin/gzip
removing old log 
/tmp/old________logs/ddddddddddddddd.log-2016.56789.xxxxxxxxxxxxxxxxx.gz
compressing log with: /bin/gzip
removing old log 
/tmp/old________logs/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.log-2016.56789.xxxxxxxxxxxxxxxxx.gz
./generate-and-test.sh: line 27:   179 Segmentation fault      (core dumped) 
logrotate -v --force --state $PWD/logrotate.state logrotate.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-- 
Pozdrawiam,
Michał "rysiek" Woźniak

Zmieniam klucz GPG :: http://rys.io/pl/147
GPG Key Transition :: http://rys.io/en/147

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to