Bug 7999 - filenames with spaces break logrotate status file
filenames with spaces break logrotate status file
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: logrotate (Show other bugs)
6.1
All Linux
medium Severity medium
: ---
: ---
Assigned To: Erik Troan
:
: 11654 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 1999-12-26 05:15 EST by Ingo Luetkebohle
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-07-13 09:15:14 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Ingo Luetkebohle 1999-12-26 05:15:04 EST
Log file names that contain whitespace are stored
without quotes in the logrotate.status file, like this:

/var/log/by machine/this log file contains spaces 1999-11-24

which does not constitute a valid status-file entry by logrotates own
standards ;-) and breaks further rotation runs. The abovementioned log
files was entered in the logrotate.conf as "/var/log/by machine/..." and
logrotate did parse that.
Comment 1 fortytwo 2000-05-13 13:26:59 EDT
Note that spaces can also crop up if you say
/var/log/samba/*
for example, because some machines have spaces in their names.

The following patch is a (pretty bad, actually) way to fix it.

It changes the format of the logrotate.status file so that the filename is on a
line by itself so that it can read by a pair of fgets() instead of just one.  A
better way would probably be something like URL-encoding the filename instead.
It will also now print out the line number in the "line too long" error.

Since this changes the format, the old /var/lib/logrotate.status file will need
to be removed or translated.

--- logrotate-3.3.2.orig/logrotate.c    Wed Jun 16 16:44:07 1999
+++ logrotate-3.3.2/logrotate.c Sat May 13 13:05:54 2000
@@ -661,7 +661,7 @@
     fprintf(f, "logrotate state -- version 1\n");

     for (i = 0; i < numStates; i++) {
-       fprintf(f, "%s %d-%d-%d\n", states[i].fn,
+       fprintf(f, "%s\n%d-%d-%d\n", states[i].fn,
                states[i].lastRotated.tm_year + 1900,
                states[i].lastRotated.tm_mon + 1,
                states[i].lastRotated.tm_mday);
@@ -717,19 +717,23 @@

     line++;

-    while (fgets(buf, sizeof(buf) - 1, f)) {
+    while (fgets(buf2, sizeof(buf2) - 1, f)) {
        line++;
-       i = strlen(buf);
-       if (buf[i - 1] != '\n') {
-           message(MESS_ERROR, "line too long in state file %s\n",
-                       stateFilename);
+       i = strlen(buf2);
+       if (buf2[i - 1] != '\n') {
+           message(MESS_ERROR, "line %d too long in state file %s\n",
+                       line, stateFilename);
            fclose(f);
            return 1;
        }
+       buf2[i-1] = '\0';

        if (i == 1) continue;

-       if (sscanf(buf, "%s %d-%d-%d\n", buf2, &year, &month, &day) != 4) {
+       fgets(buf, sizeof(buf) - 1, f);
+       line++;
+
+       if (sscanf(buf, "%d-%d-%d\n", &year, &month, &day) != 3) {
            message(MESS_ERROR, "bad line %d in state file %s\n",
                    line, stateFilename);
            fclose(f);
Comment 2 Erik Troan 2000-06-18 13:29:41 EDT
*** Bug 11654 has been marked as a duplicate of this bug. ***
Comment 3 Erik Troan 2000-07-13 09:15:12 EDT
This is (finally) fixed in logrotate 3.4, which will show up in rawhide soon.

Note You need to log in before you can comment on or make changes to this bug.