--- logrotate-3.6.2.orig/config.c Tue Jan 29 23:20:02 2002 +++ logrotate-3.6.2/config.c Sat Mar 23 21:34:20 2002 @@ -24,7 +24,7 @@ #endif static char * defTabooExts[] = { ".rpmsave", ".rpmorig", "~", ",v", - ".rpmnew", ".swp" }; + ".rpmnew", ".swp", ".gz", ".bz2", ".#" }; static int defTabooCount = sizeof(defTabooExts) / sizeof(char *); /* I shouldn't use globals here :-( */ @@ -126,33 +126,97 @@ static char * readAddress(const char * c return NULL; } +/* + * Returns false if given name ending with on of taboo suffixes. + */ +static int +valid_name(const char *name) +{ + int i; + unsigned n_len; + + if (strchr(name, '\'')) { + message(MESS_DEBUG, "Ignoring %s, because of \"'\" symbol\n", name); + return 0; + } + + n_len = strlen(name); + for (i = 0; i < tabooCount; ++i) { + const char *t = tabooExts[i]; + unsigned t_len; + + if (!t) + continue; + + t_len = strlen(t); + if (n_len < t_len) + continue; + + if (!memcmp(name + n_len - t_len, t, t_len)) { + message(MESS_DEBUG, + "Ignoring %s, because of \"%s\" ending\n", name, t); + return 0; + } + + if (!strcmp(t, ".#")) { /* .# suffix means .number */ + const char *p = strrchr(name, '.'); + + if (p) { + char *endp; + long suffix; + + errno = 0; + suffix = strtol(p + 1, &endp, 10); + if (!errno && !*endp && (suffix > 0)) { + message(MESS_DEBUG, + "Ignoring %s, because of \"%s\" ending\n", + name, p); + return 0; + } + } + } + } + + return 1; +} + +/* + * Returns false if given logfile name isn't allowed to rotate. + */ +static int +valid_logname(const char *name) +{ + struct stat stb; + + if (lstat(name, &stb) < 0) { + message(MESS_DEBUG, "Ignoring missing %s: %s\n", + name, strerror(errno)); + return 0; + } + if (!S_ISREG(stb.st_mode)) { + message(MESS_DEBUG, + "Ignoring %s, because of wrong file type %#x\n", + name, stb.st_mode); + return 0; + } + return valid_name(name); +} + /** This function will be called as the 'select' method in the scandir(3) function-call. */ static int checkFilelist(struct dirent const *ent) { - size_t i; - assert(ent!=0); + /* Check entry for validity. */ + if (!ent || !ent->d_name) + return 0; /* Check if ent->d_name is '.' or '..'; if so, return false */ if (ent->d_name[0] == '.' && (!ent->d_name[1] || (ent->d_name[1] == '.' && !ent->d_name[2]))) return 0; - /* Check if ent->d_name is ending in a taboo-extension; if so, return - false */ - for (i = 0; i < tabooCount; i++) { - if (!strcmp(ent->d_name + strlen(ent->d_name) - - strlen(tabooExts[i]), tabooExts[i])) { - message(MESS_DEBUG, "Ignoring %s, because of %s " - "ending\n", ent->d_name, tabooExts[i]); - - return 0; - } - } - - /* All checks have been passed; return true */ - return 1; + return valid_name (ent->d_name); } int readConfigPath(const char * path, logInfo * defConfig, @@ -267,9 +331,10 @@ static int readConfigFile(const char * c close(fd); return 1; } + if (!S_ISREG(sb.st_mode)) { - message(MESS_DEBUG, "Ignoring %s because it's not a regular file.\n", - configFile); + message(MESS_DEBUG, "Ignoring %s, because of wrong file type %#x\n", + configFile, sb.st_mode); close(fd); return 0; } @@ -788,8 +853,7 @@ static int readConfigFile(const char * c for (i = 0; i < globResult.gl_pathc; i++) { /* if we glob directories we can get false matches */ - if (!lstat(globResult.gl_pathv[i], &sb) && - S_ISDIR(sb.st_mode)) + if ( !valid_logname( globResult.gl_pathv[i] ) ) continue; for (j = 0; j < *numLogsPtr - 1; j++) {