commit e741d421bbab7fe22414f2f6a27bd2d3c08a529a Author: overweight <5324761+overweight@user.noreply.gitee.com> Date: Mon Sep 30 11:02:46 2019 -0400 Package init diff --git a/0001-logrotate-3.14.0-man-version.patch b/0001-logrotate-3.14.0-man-version.patch new file mode 100644 index 0000000..d2f8608 --- /dev/null +++ b/0001-logrotate-3.14.0-man-version.patch @@ -0,0 +1,38 @@ +From b0d067cfba64956893fc095bb37f8c767f5a910e Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Mon, 6 Aug 2018 17:13:31 +0200 +Subject: [PATCH] logrotate.8: document the --version option + +reason: In order to improve usability of packages, project Man + Page Scan was created and its task is to provide consistency + of man pages (and documentation in general) + +The man page now covers all the options that are listed +by `logrotate --help`. + +Bug: https://bugzilla.redhat.com/1611498 + +Upstream-commit: 4088ef987df2ec48cc3d968eb87ad27c840fa2d8 +Signed-off-by: Kamil Dudka +--- + logrotate.8.in | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/logrotate.8.in b/logrotate.8.in +index 004229e..5ef09c5 100644 +--- a/logrotate.8.in ++++ b/logrotate.8.in +@@ -87,6 +87,10 @@ Prints a short usage message. + \fB\-v\fR, \fB\-\-verbose\fR + Turns on verbose mode, for example to display messages during rotation. + ++.TP ++\fB\-\-version\fR ++Display version information. ++ + .SH CONFIGURATION FILE + + \fBlogrotate\fR reads everything about the log files it should be handling +-- +2.17.1 + diff --git a/0002-logrotate-3.14.0-coverity.patch b/0002-logrotate-3.14.0-coverity.patch new file mode 100644 index 0000000..5ce0999 --- /dev/null +++ b/0002-logrotate-3.14.0-coverity.patch @@ -0,0 +1,642 @@ +From a4ac21e9a8cfe8a73471a195308a742e07d7fe8d Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Wed, 1 Aug 2018 15:32:38 +0200 +Subject: [PATCH 1/3] readConfigFile: assign and check 'key' separately + +reason: assign and check 'key' separately + +https://github.com/logrotate/logrotate/commit/db33a0dd8b9b22deee7a6ff2e33fe037ec62c5a1 + +... to make the code readable. No changes in behavior intended +by this commit. +--- + config.c | 312 +++++++++++++++++++++++++++---------------------------- + 1 file changed, 152 insertions(+), 160 deletions(-) + +diff --git a/config.c b/config.c +index 84db36f..d2fba10 100644 +--- a/config.c ++++ b/config.c +@@ -1037,7 +1037,8 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + } + + if (isalpha((unsigned char)*start)) { +- if ((key = isolateWord(&start, &buf, length)) == NULL) ++ key = isolateWord(&start, &buf, length); ++ if (key == NULL) + continue; + if (!strcmp(key, "compress")) { + newlog->flags |= LOG_FLAG_COMPRESS; +@@ -1191,16 +1192,16 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + } + } else if (!strcmp(key, "shredcycles")) { + free(key); +- if ((key = isolateValue(configFile, lineNum, "shred cycles", +- &start, &buf, length)) != NULL) { +- newlog->shred_cycles = strtoul(key, &chptr, 0); +- if (*chptr || newlog->shred_cycles < 0) { +- message(MESS_ERROR, "%s:%d bad shred cycles '%s'\n", +- configFile, lineNum, key); +- goto error; +- } ++ key = isolateValue(configFile, lineNum, "shred cycles", ++ &start, &buf, length); ++ if (key == NULL) ++ continue; ++ newlog->shred_cycles = strtoul(key, &chptr, 0); ++ if (*chptr || newlog->shred_cycles < 0) { ++ message(MESS_ERROR, "%s:%d bad shred cycles '%s'\n", ++ configFile, lineNum, key); ++ goto error; + } +- else continue; + } else if (!strcmp(key, "hourly")) { + newlog->criterium = ROT_HOURLY; + } else if (!strcmp(key, "daily")) { +@@ -1232,59 +1233,53 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + newlog->criterium = ROT_YEARLY; + } else if (!strcmp(key, "rotate")) { + free(key); +- if ((key = isolateValue +- (configFile, lineNum, "rotate count", &start, +- &buf, length)) != NULL) { +- +- newlog->rotateCount = strtoul(key, &chptr, 0); +- if (*chptr || newlog->rotateCount < 0) { +- message(MESS_ERROR, +- "%s:%d bad rotation count '%s'\n", +- configFile, lineNum, key); +- RAISE_ERROR(); +- } ++ key = isolateValue(configFile, lineNum, "rotate count", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ newlog->rotateCount = strtoul(key, &chptr, 0); ++ if (*chptr || newlog->rotateCount < 0) { ++ message(MESS_ERROR, ++ "%s:%d bad rotation count '%s'\n", ++ configFile, lineNum, key); ++ RAISE_ERROR(); + } +- else continue; + } else if (!strcmp(key, "start")) { + free(key); +- if ((key = isolateValue +- (configFile, lineNum, "start count", &start, +- &buf, length)) != NULL) { +- +- newlog->logStart = strtoul(key, &chptr, 0); +- if (*chptr || newlog->logStart < 0) { +- message(MESS_ERROR, "%s:%d bad start count '%s'\n", +- configFile, lineNum, key); +- RAISE_ERROR(); +- } ++ key = isolateValue(configFile, lineNum, "start count", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ newlog->logStart = strtoul(key, &chptr, 0); ++ if (*chptr || newlog->logStart < 0) { ++ message(MESS_ERROR, "%s:%d bad start count '%s'\n", ++ configFile, lineNum, key); ++ RAISE_ERROR(); + } +- else continue; + } else if (!strcmp(key, "minage")) { + free(key); +- if ((key = isolateValue +- (configFile, lineNum, "minage count", &start, +- &buf, length)) != NULL) { +- newlog->rotateMinAge = strtoul(key, &chptr, 0); +- if (*chptr || newlog->rotateMinAge < 0) { +- message(MESS_ERROR, "%s:%d bad minimum age '%s'\n", +- configFile, lineNum, start); +- RAISE_ERROR(); +- } ++ key = isolateValue(configFile, lineNum, "minage count", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ newlog->rotateMinAge = strtoul(key, &chptr, 0); ++ if (*chptr || newlog->rotateMinAge < 0) { ++ message(MESS_ERROR, "%s:%d bad minimum age '%s'\n", ++ configFile, lineNum, start); ++ RAISE_ERROR(); + } +- else continue; + } else if (!strcmp(key, "maxage")) { + free(key); +- if ((key = isolateValue +- (configFile, lineNum, "maxage count", &start, +- &buf, length)) != NULL) { +- newlog->rotateAge = strtoul(key, &chptr, 0); +- if (*chptr || newlog->rotateAge < 0) { +- message(MESS_ERROR, "%s:%d bad maximum age '%s'\n", +- configFile, lineNum, start); +- RAISE_ERROR(); +- } ++ key = isolateValue(configFile, lineNum, "maxage count", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ newlog->rotateAge = strtoul(key, &chptr, 0); ++ if (*chptr || newlog->rotateAge < 0) { ++ message(MESS_ERROR, "%s:%d bad maximum age '%s'\n", ++ configFile, lineNum, start); ++ RAISE_ERROR(); + } +- else continue; + } else if (!strcmp(key, "errors")) { + message(MESS_DEBUG, + "%s: %d: the errors directive is deprecated and no longer used.\n", +@@ -1337,48 +1332,48 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + continue; + } + free(key); +- if ((key = isolateValue(configFile, lineNum, "tabooext", &start, +- &buf, length)) != NULL) { +- endtag = key; +- if (*endtag == '+') { ++ key = isolateValue(configFile, lineNum, "tabooext", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ endtag = key; ++ if (*endtag == '+') { ++ endtag++; ++ while (isspace((unsigned char)*endtag) && *endtag) + endtag++; +- while (isspace((unsigned char)*endtag) && *endtag) +- endtag++; +- } else { +- free_2d_array(tabooPatterns, tabooCount); +- tabooCount = 0; +- /* realloc of NULL is safe by definition */ +- tabooPatterns = NULL; +- } +- +- while (*endtag) { +- int bytes; +- char *pattern = NULL; ++ } else { ++ free_2d_array(tabooPatterns, tabooCount); ++ tabooCount = 0; ++ /* realloc of NULL is safe by definition */ ++ tabooPatterns = NULL; ++ } + +- chptr = endtag; +- while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr) +- chptr++; ++ while (*endtag) { ++ int bytes; ++ char *pattern = NULL; + +- /* accept only non-empty patterns to avoid exclusion of everything */ +- if (endtag < chptr) { +- tabooPatterns = realloc(tabooPatterns, sizeof(*tabooPatterns) * +- (tabooCount + 1)); +- bytes = asprintf(&pattern, "*%.*s", (int)(chptr - endtag), endtag); ++ chptr = endtag; ++ while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr) ++ chptr++; + +- /* should test for malloc() failure */ +- assert(bytes != -1); +- tabooPatterns[tabooCount] = pattern; +- tabooCount++; +- } ++ /* accept only non-empty patterns to avoid exclusion of everything */ ++ if (endtag < chptr) { ++ tabooPatterns = realloc(tabooPatterns, sizeof(*tabooPatterns) * ++ (tabooCount + 1)); ++ bytes = asprintf(&pattern, "*%.*s", (int)(chptr - endtag), endtag); + +- endtag = chptr; +- if (*endtag == ',') +- endtag++; +- while (*endtag && isspace((unsigned char)*endtag)) +- endtag++; ++ /* should test for malloc() failure */ ++ assert(bytes != -1); ++ tabooPatterns[tabooCount] = pattern; ++ tabooCount++; + } ++ ++ endtag = chptr; ++ if (*endtag == ',') ++ endtag++; ++ while (*endtag && isspace((unsigned char)*endtag)) ++ endtag++; + } +- else continue; + } else if (!strcmp(key, "taboopat")) { + if (newlog != defConfig) { + message(MESS_ERROR, +@@ -1389,68 +1384,68 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + continue; + } + free(key); +- if ((key = isolateValue(configFile, lineNum, "taboopat", &start, +- &buf, length)) != NULL) { +- endtag = key; +- if (*endtag == '+') { ++ key = isolateValue(configFile, lineNum, "taboopat", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ ++ endtag = key; ++ if (*endtag == '+') { ++ endtag++; ++ while (isspace((unsigned char)*endtag) && *endtag) + endtag++; +- while (isspace((unsigned char)*endtag) && *endtag) +- endtag++; +- } else { +- free_2d_array(tabooPatterns, tabooCount); +- tabooCount = 0; +- /* realloc of NULL is safe by definition */ +- tabooPatterns = NULL; +- } ++ } else { ++ free_2d_array(tabooPatterns, tabooCount); ++ tabooCount = 0; ++ /* realloc of NULL is safe by definition */ ++ tabooPatterns = NULL; ++ } + +- while (*endtag) { +- int bytes; +- char *pattern = NULL; ++ while (*endtag) { ++ int bytes; ++ char *pattern = NULL; + +- chptr = endtag; +- while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr) +- chptr++; ++ chptr = endtag; ++ while (!isspace((unsigned char)*chptr) && *chptr != ',' && *chptr) ++ chptr++; + +- tabooPatterns = realloc(tabooPatterns, sizeof(*tabooPatterns) * +- (tabooCount + 1)); +- bytes = asprintf(&pattern, "%.*s", (int)(chptr - endtag), endtag); ++ tabooPatterns = realloc(tabooPatterns, sizeof(*tabooPatterns) * ++ (tabooCount + 1)); ++ bytes = asprintf(&pattern, "%.*s", (int)(chptr - endtag), endtag); + +- /* should test for malloc() failure */ +- assert(bytes != -1); +- tabooPatterns[tabooCount] = pattern; +- tabooCount++; ++ /* should test for malloc() failure */ ++ assert(bytes != -1); ++ tabooPatterns[tabooCount] = pattern; ++ tabooCount++; + +- endtag = chptr; +- if (*endtag == ',') +- endtag++; +- while (*endtag && isspace((unsigned char)*endtag)) +- endtag++; +- } ++ endtag = chptr; ++ if (*endtag == ',') ++ endtag++; ++ while (*endtag && isspace((unsigned char)*endtag)) ++ endtag++; + } +- else continue; + } else if (!strcmp(key, "include")) { + free(key); +- if ((key = isolateValue(configFile, lineNum, "include", &start, +- &buf, length)) != NULL) { +- +- message(MESS_DEBUG, "including %s\n", key); +- if (recursion_depth >= MAX_NESTING) { +- message(MESS_ERROR, "%s:%d include nesting too deep\n", +- configFile, lineNum); +- logerror = 1; +- continue; +- } ++ key = isolateValue(configFile, lineNum, "include", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ message(MESS_DEBUG, "including %s\n", key); ++ if (recursion_depth >= MAX_NESTING) { ++ message(MESS_ERROR, "%s:%d include nesting too deep\n", ++ configFile, lineNum); ++ logerror = 1; ++ continue; ++ } + +- ++recursion_depth; +- rv = readConfigPath(key, newlog); +- --recursion_depth; ++ ++recursion_depth; ++ rv = readConfigPath(key, newlog); ++ --recursion_depth; + +- if (rv) { +- logerror = 1; +- continue; +- } ++ if (rv) { ++ logerror = 1; ++ continue; + } +- else continue; + } else if (!strcmp(key, "olddir")) { + freeLogItem (oldDir); + +@@ -1460,28 +1455,23 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + } + message(MESS_DEBUG, "olddir is now %s\n", newlog->oldDir); + } else if (!strcmp(key, "extension")) { +- if ((key = isolateValue +- (configFile, lineNum, "extension name", &start, +- &buf, length)) != NULL) { +- freeLogItem (extension); +- newlog->extension = key; +- key = NULL; +- } +- else continue; +- +- message(MESS_DEBUG, "extension is now %s\n", +- newlog->extension); ++ key = isolateValue(configFile, lineNum, "extension name", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ freeLogItem (extension); ++ newlog->extension = key; ++ key = NULL; ++ message(MESS_DEBUG, "extension is now %s\n", newlog->extension); + + } else if (!strcmp(key, "addextension")) { +- if ((key = isolateValue +- (configFile, lineNum, "addextension name", &start, +- &buf, length)) != NULL) { +- freeLogItem (addextension); +- newlog->addextension = key; +- key = NULL; +- } +- else continue; +- ++ key = isolateValue(configFile, lineNum, "addextension name", &start, ++ &buf, length); ++ if (key == NULL) ++ continue; ++ freeLogItem (addextension); ++ newlog->addextension = key; ++ key = NULL; + message(MESS_DEBUG, "addextension is now %s\n", + newlog->addextension); + +@@ -1827,7 +1817,8 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + break; + case STATE_LOAD_SCRIPT: + case STATE_LOAD_SCRIPT | STATE_SKIP_CONFIG: +- if ((key = isolateWord(&start, &buf, length)) == NULL) ++ key = isolateWord(&start, &buf, length); ++ if (key == NULL) + continue; + + if (strcmp(key, "endscript") == 0) { +@@ -1862,7 +1853,8 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + newlog = defConfig; + } + else { +- if ((key = isolateWord(&start, &buf, length)) == NULL) ++ key = isolateWord(&start, &buf, length); ++ if (key == NULL) + continue; + if ( + (strcmp(key, "postrotate") == 0) || +-- +2.17.1 + + +From a3a955494999bd4861f14b846c345cbc96715262 Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Wed, 1 Aug 2018 15:09:40 +0200 +Subject: [PATCH 2/3] readConfigFile: assign and free 'key' consistently + +reason: assign and free 'key' consistently + +https://github.com/logrotate/logrotate/commit/7c1d87441c79cf550f0a50bf216b517f75d10411 + +This commit fixes the following memory leaks (detected by Coverity): + +Error: RESOURCE_LEAK: +config.c:1466: overwrite_var: Overwriting "key" in "key = isolateValue(configFile, lineNum, "extension name", &start, &buf, length)" leaks the storage that "key" points to. + +Error: RESOURCE_LEAK: +config.c:1479: overwrite_var: Overwriting "key" in "key = isolateValue(configFile, lineNum, "addextension name", &start, &buf, length)" leaks the storage that "key" points to. + +Error: RESOURCE_LEAK: +config.c:1043: alloc_fn: Storage is returned from allocation function "isolateWord". +config.c:219:2: alloc_fn: Storage is returned from allocation function "strndup". +config.c:219:2: assign: Assigning: "key" = "strndup(start, endtag - start)". +config.c:221:2: return_alloc: Returning allocated memory "key". +config.c:1043: var_assign: Assigning: "key" = storage returned from "isolateWord(&start, &buf, length)". +config.c:1928: leaked_storage: Variable "key" going out of scope leaks the storage it points to. + +Error: RESOURCE_LEAK: +config.c:1153: alloc_fn: Storage is returned from allocation function "isolateValue". +config.c:204:2: alloc_fn: Storage is returned from allocation function "isolateLine". +config.c:178:2: alloc_fn: Storage is returned from allocation function "strndup". +config.c:178:2: assign: Assigning: "key" = "strndup(start, endtag - start + 1L)". +config.c:180:2: return_alloc: Returning allocated memory "key". +config.c:204:2: return_alloc_fn: Directly returning storage allocated by "isolateLine". +config.c:1153: var_assign: Assigning: "key" = storage returned from "isolateValue(configFile, lineNum, opt, &start, &buf, length)". +config.c:1928: leaked_storage: Variable "key" going out of scope leaks the storage it points to. + +Error: RESOURCE_LEAK: +config.c:1219: alloc_fn: Storage is returned from allocation function "isolateLine". +config.c:178:2: alloc_fn: Storage is returned from allocation function "strndup". +config.c:178:2: assign: Assigning: "key" = "strndup(start, endtag - start + 1L)". +config.c:180:2: return_alloc: Returning allocated memory "key". +config.c:1219: var_assign: Assigning: "key" = storage returned from "isolateLine(&start, &buf, length)". +config.c:1928: leaked_storage: Variable "key" going out of scope leaks the storage it points to. + +Closes #208 +--- + config.c | 19 +++++++------------ + 1 file changed, 7 insertions(+), 12 deletions(-) + +diff --git a/config.c b/config.c +index d2fba10..39c9bc7 100644 +--- a/config.c ++++ b/config.c +@@ -1022,10 +1022,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + + start = buf; + for (start = buf; start - buf < length; start++) { +- if (key) { +- free(key); +- key = NULL; +- } + switch (state) { + case STATE_DEFAULT: + if (isblank((unsigned char)*start)) +@@ -1037,6 +1033,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + } + + if (isalpha((unsigned char)*start)) { ++ free(key); + key = isolateWord(&start, &buf, length); + if (key == NULL) + continue; +@@ -1455,6 +1452,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + } + message(MESS_DEBUG, "olddir is now %s\n", newlog->oldDir); + } else if (!strcmp(key, "extension")) { ++ free(key); + key = isolateValue(configFile, lineNum, "extension name", &start, + &buf, length); + if (key == NULL) +@@ -1465,6 +1463,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + message(MESS_DEBUG, "extension is now %s\n", newlog->extension); + + } else if (!strcmp(key, "addextension")) { ++ free(key); + key = isolateValue(configFile, lineNum, "addextension name", &start, + &buf, length); + if (key == NULL) +@@ -1557,8 +1556,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + if (*start != '\n') + state = STATE_SKIP_LINE; + } +- free(key); +- key = NULL; + } else if (*start == '/' || *start == '"' || *start == '\'' + #ifdef GLOB_TILDE + || *start == '~' +@@ -1817,6 +1814,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + break; + case STATE_LOAD_SCRIPT: + case STATE_LOAD_SCRIPT | STATE_SKIP_CONFIG: ++ free(key); + key = isolateWord(&start, &buf, length); + if (key == NULL) + continue; +@@ -1853,6 +1851,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + newlog = defConfig; + } + else { ++ free(key); + key = isolateWord(&start, &buf, length); + if (key == NULL) + continue; +@@ -1884,8 +1883,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + state = STATE_SKIP_LINE | STATE_SKIP_CONFIG; + } + } +- free(key); +- key = NULL; + } + break; + default: +@@ -1893,10 +1890,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + "%s: %d: readConfigFile() unknown state\n", + configFile, lineNum); + } +- if (key) { +- free(key); +- key = NULL; +- } + if (*start == '\n') { + lineNum++; + } +@@ -1910,6 +1903,8 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + goto error; + } + ++ free(key); ++ + munmap(buf, (size_t) length); + close(fd); + return logerror; +-- +2.17.1 + + +From 771af94fd6c6299a7cb3d20c8b247591775653d3 Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Wed, 1 Aug 2018 16:06:27 +0200 +Subject: [PATCH 3/3] readConfigFile: simplify code of prerotateSingleLog() + +reason: simplify code of prerotateSingleLog() + +https://github.com/logrotate/logrotate/commit/311023530d90ba6cf8535b80ea20b4abc7cfe9a3 + +... to eliminate a use-after-free false positive reported by Coverity: + +Error: USE_AFTER_FREE: +logrotate.c:1800: freed_arg: "free" frees "oldName". +logrotate.c:1779: use_after_free: Using freed pointer "oldName". + +Closes #209 +--- + logrotate.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/logrotate.c b/logrotate.c +index 02d45e9..95fd70b 100644 +--- a/logrotate.c ++++ b/logrotate.c +@@ -1353,7 +1353,7 @@ static int prerotateSingleLog(struct logInfo *log, int logNum, + struct logState *state, struct logNames *rotNames) + { + struct tm now = *localtime(&nowSecs); +- char *oldName, *newName = NULL; ++ char *oldName = NULL; + const char *compext = ""; + const char *fileext = ""; + int hasErrors = 0; +@@ -1670,6 +1670,7 @@ static int prerotateSingleLog(struct logInfo *log, int logNum, + free(glob_pattern); + } else { + int i; ++ char *newName = NULL; + if (log->rotateAge) { + struct stat fst_buf; + for (i = 1; i <= rotateCount + 1; i++) { +@@ -1697,7 +1698,6 @@ static int prerotateSingleLog(struct logInfo *log, int logNum, + compext) < 0) { + message(MESS_FATAL, "could not allocate disposeName memory\n"); + } +- newName = strdup(oldName); + + rotNames->disposeName = strdup(oldName); + +@@ -1711,6 +1711,8 @@ static int prerotateSingleLog(struct logInfo *log, int logNum, + if (asprintf(&oldName, "%s/%s.%d%s%s", rotNames->dirName, + rotNames->baseName, i, fileext, compext) < 0) { + message(MESS_FATAL, "could not allocate oldName memory\n"); ++ oldName = NULL; ++ break; + } + + message(MESS_DEBUG, +@@ -1727,11 +1729,9 @@ static int prerotateSingleLog(struct logInfo *log, int logNum, + hasErrors = 1; + } + } +- if (hasErrors || i - 1 < 0) +- free(oldName); +- + } + free(newName); ++ free(oldName); + } /* !LOG_FLAG_DATEEXT */ + + if (log->flags & LOG_FLAG_DATEEXT) { +-- +2.17.1 + diff --git a/config-add-variable-initialization-Wconditional-unin.patch b/config-add-variable-initialization-Wconditional-unin.patch new file mode 100644 index 0000000..f45958d --- /dev/null +++ b/config-add-variable-initialization-Wconditional-unin.patch @@ -0,0 +1,34 @@ +From 2c3aa286f7eb25edf25b22b7c32b966543aeda2c Mon Sep 17 00:00:00 2001 +From: Sami Kerola +Date: Mon, 25 Feb 2019 20:10:32 +0000 +Subject: [PATCH] config: add variable initialization + [-Wconditional-uninitialized] + +reason:add variable initialization + +https://github.com/logrotate/logrotate/pull/240/commits + +config.c:314:17: warning: variable 'm' may be uninitialized when used here +config.c:287:19: note: initialize the variable 'm' to silence this warning + +Signed-off-by: Sami Kerola +--- + config.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/config.c b/config.c +index 239c943..07bd374 100644 +--- a/config.c ++++ b/config.c +@@ -304,7 +304,7 @@ static int readModeUidGid(const char *configFile, int lineNum, char *key, + gid_t *pGid) + { + char u[200], g[200]; +- unsigned int m; ++ unsigned int m = 0; + char tmp; + int rc; + +-- +1.8.3.1 + diff --git a/config-logrotate-fix-couple-printf-format-specifiers.patch b/config-logrotate-fix-couple-printf-format-specifiers.patch new file mode 100644 index 0000000..6d649f4 --- /dev/null +++ b/config-logrotate-fix-couple-printf-format-specifiers.patch @@ -0,0 +1,99 @@ +From 99ff59b39eafecb20063a06704caf17e767c34ab Mon Sep 17 00:00:00 2001 +From: Sami Kerola +Date: Thu, 17 May 2018 21:03:31 +0100 +Subject: [PATCH 15/39] config / logrotate: fix couple printf format specifiers + +reason: fix couple printf format specifiers + +https://github.com/logrotate/logrotate/pull/200 + +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +All of these are are warnings similar to one below. + +config.c:369:59: warning: format ‘%d’ expects argument of type ‘int’, but +argument 4 has type ‘uid_t’ {aka ‘unsigned int’} [-Wformat=] + +Signed-off-by: Sami Kerola + +Closes #200 +--- + config.c | 2 +- + logrotate.c | 14 +++++++------- + 2 files changed, 8 insertions(+), 8 deletions(-) + +diff --git a/config.c b/config.c +index 4162cca..53b7416 100644 +--- a/config.c ++++ b/config.c +@@ -360,7 +360,7 @@ static int do_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { + if (mkdir(path, mode) == 0) { + /* newly created directory, set the owner and permissions */ + if (chown(path, uid, gid) != 0) { +- message(MESS_ERROR, "error setting owner of %s to uid %d and gid %d: %s\n", ++ message(MESS_ERROR, "error setting owner of %s to uid %u and gid %u: %s\n", + path, uid, gid, strerror(errno)); + return -1; + } +diff --git a/logrotate.c b/logrotate.c +index 01836cf..4fd546f 100644 +--- a/logrotate.c ++++ b/logrotate.c +@@ -156,10 +156,10 @@ int switch_user(uid_t user, gid_t group) { + save_euid = geteuid(); + if (save_euid == user && save_egid == group) + return 0; +- message(MESS_DEBUG, "switching euid to %d and egid to %d\n", ++ message(MESS_DEBUG, "switching euid to %u and egid to %u\n", + user, group); + if (setegid(group) || seteuid(user)) { +- message(MESS_ERROR, "error switching euid to %d and egid to %d: %s\n", ++ message(MESS_ERROR, "error switching euid to %u and egid to %u: %s\n", + user, group, strerror(errno)); + return 1; + } +@@ -179,10 +179,10 @@ static int switch_user_permanently(const struct logInfo *log) { + message(MESS_ERROR, "error getting rid of euid != uid\n"); + return 1; + } +- message(MESS_DEBUG, "switching uid to %d and gid to %d\n", ++ message(MESS_DEBUG, "switching uid to %u and gid to %u\n", + user, group); + if (setgid(group) || setuid(user)) { +- message(MESS_ERROR, "error switching euid to %d and egid to %d: %s\n", ++ message(MESS_ERROR, "error switching euid to %u and egid to %u: %s\n", + user, group, strerror(errno)); + return 1; + } +@@ -239,7 +239,7 @@ static int allocateHash(unsigned int hs) + if (hs < HASH_SIZE_MIN) + hs = HASH_SIZE_MIN; + +- message(MESS_DEBUG, "Allocating hash table for state file, size %d entries\n", ++ message(MESS_DEBUG, "Allocating hash table for state file, size %u entries\n", + hs); + + states = calloc(hs, sizeof(struct logStateList *)); +@@ -540,7 +540,7 @@ static int createOutputFile(char *fileName, int flags, struct stat *sb, + + if ((sb_create.st_uid != sb->st_uid || sb_create.st_gid != sb->st_gid) && + fchown(fd, sb->st_uid, sb->st_gid)) { +- message(MESS_ERROR, "error setting owner of %s to uid %d and gid %d: %s\n", ++ message(MESS_ERROR, "error setting owner of %s to uid %u and gid %u: %s\n", + fileName, sb->st_uid, sb->st_gid, strerror(errno)); + close(fd); + return -1; +@@ -1993,7 +1993,7 @@ static int rotateLogSet(struct logInfo *log, int force) + message(MESS_DEBUG, "%jd bytes ", (intmax_t)log->threshold); + break; + default: +- message(MESS_DEBUG, "rotateLogSet() does not have case for: %d ", log->criterium); ++ message(MESS_DEBUG, "rotateLogSet() does not have case for: %u ", log->criterium); + } + } + +-- +1.8.3.1 + diff --git a/do_mkdir-fix-time-of-check-time-of-use-race-conditio.patch b/do_mkdir-fix-time-of-check-time-of-use-race-conditio.patch new file mode 100644 index 0000000..dc974ef --- /dev/null +++ b/do_mkdir-fix-time-of-check-time-of-use-race-conditio.patch @@ -0,0 +1,87 @@ +From 22892fb94b7da0018802363637928d21b7f00687 Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Mon, 30 Apr 2018 18:46:13 +0200 +Subject: [PATCH 14/39] do_mkdir: fix time-of-check/time-of-use race condition + +reason: fix time-of-check/time-of-use race condition + +https://github.com/logrotate/logrotate/pull/196 + +... detected by Coverity Analysis + +Error: TOCTOU: +config.c:362: fs_check_call: Calling function "stat" to perform check on "path". +config.c:363: toctou: Calling function "mkdir" that uses "path" after a check function. This can cause a time-of-check, time-of-use race condition. + +Closes #196 +--- + config.c | 49 ++++++++++++++++++++++++++----------------------- + 1 file changed, 26 insertions(+), 23 deletions(-) + +diff --git a/config.c b/config.c +index 9cc66ac..4162cca 100644 +--- a/config.c ++++ b/config.c +@@ -357,33 +357,36 @@ static char *readAddress(const char *configFile, int lineNum, const char *key, + } + + static int do_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { +- struct stat sb; +- +- if (stat(path, &sb) != 0) { +- if (mkdir(path, mode) != 0 && errno != EEXIST) { +- message(MESS_ERROR, "error creating %s: %s\n", +- path, strerror(errno)); +- return -1; +- } +- if (chown(path, uid, gid) != 0) { +- message(MESS_ERROR, "error setting owner of %s to uid %d and gid %d: %s\n", +- path, uid, gid, strerror(errno)); +- return -1; +- } +- if (chmod(path, mode) != 0) { +- message(MESS_ERROR, "error setting permissions of %s to 0%o: %s\n", +- path, mode, strerror(errno)); +- return -1; +- } ++ if (mkdir(path, mode) == 0) { ++ /* newly created directory, set the owner and permissions */ ++ if (chown(path, uid, gid) != 0) { ++ message(MESS_ERROR, "error setting owner of %s to uid %d and gid %d: %s\n", ++ path, uid, gid, strerror(errno)); ++ return -1; + } +- else if (!S_ISDIR(sb.st_mode)) { +- message(MESS_ERROR, "path %s already exists, but it is not a directory\n", +- path); +- errno = ENOTDIR; +- return -1; ++ ++ if (chmod(path, mode) != 0) { ++ message(MESS_ERROR, "error setting permissions of %s to 0%o: %s\n", ++ path, mode, strerror(errno)); ++ return -1; + } + + return 0; ++ } ++ ++ if (errno == EEXIST) { ++ /* path already exists, check whether it is a directory or not */ ++ struct stat sb; ++ if ((stat(path, &sb) == 0) && S_ISDIR(sb.st_mode)) ++ return 0; ++ ++ message(MESS_ERROR, "path %s already exists, but it is not a directory\n", path); ++ errno = ENOTDIR; ++ return -1; ++ } ++ ++ message(MESS_ERROR, "error creating %s: %s\n", path, strerror(errno)); ++ return -1; + } + + static int mkpath(const char *path, mode_t mode, uid_t uid, gid_t gid) { +-- +1.8.3.1 + diff --git a/explicitly-cast-uid_t-and-gid_t-to-unsigned-int.patch b/explicitly-cast-uid_t-and-gid_t-to-unsigned-int.patch new file mode 100644 index 0000000..cd8ed62 --- /dev/null +++ b/explicitly-cast-uid_t-and-gid_t-to-unsigned-int.patch @@ -0,0 +1,84 @@ +From 6563e6551657b63898c7387fd56bb2f3ee115fa1 Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Wed, 1 Aug 2018 11:42:08 +0200 +Subject: [PATCH 16/39] logrotate: explicitly cast uid_t and gid_t to unsigned int + +reason: explicitly cast uid_t and gid_t to unsigned int + +https://github.com/logrotate/logrotate/commit/6563e6551657b63898c7387fd56bb2f3ee115fa1 + +... before passing them to the %u conversion in printf() invocation. +The uid_t and gid_t types do not need to be the same as unsigned int +on all supported platforms. + +Closes #200 +--- + config.c | 2 +- + logrotate.c | 13 +++++++------ + 2 files changed, 8 insertions(+), 7 deletions(-) + +diff --git a/config.c b/config.c +index 53b7416..960ee9b 100644 +--- a/config.c ++++ b/config.c +@@ -361,7 +361,7 @@ static int do_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { + /* newly created directory, set the owner and permissions */ + if (chown(path, uid, gid) != 0) { + message(MESS_ERROR, "error setting owner of %s to uid %u and gid %u: %s\n", +- path, uid, gid, strerror(errno)); ++ path, (unsigned) uid, (unsigned) gid, strerror(errno)); + return -1; + } + +diff --git a/logrotate.c b/logrotate.c +index 4fd546f..46f10a2 100644 +--- a/logrotate.c ++++ b/logrotate.c +@@ -157,10 +157,10 @@ int switch_user(uid_t user, gid_t group) { + if (save_euid == user && save_egid == group) + return 0; + message(MESS_DEBUG, "switching euid to %u and egid to %u\n", +- user, group); ++ (unsigned) user, (unsigned) group); + if (setegid(group) || seteuid(user)) { + message(MESS_ERROR, "error switching euid to %u and egid to %u: %s\n", +- user, group, strerror(errno)); ++ (unsigned) user, (unsigned) group, strerror(errno)); + return 1; + } + return 0; +@@ -180,10 +180,10 @@ static int switch_user_permanently(const struct logInfo *log) { + return 1; + } + message(MESS_DEBUG, "switching uid to %u and gid to %u\n", +- user, group); ++ (unsigned) user, (unsigned) group); + if (setgid(group) || setuid(user)) { + message(MESS_ERROR, "error switching euid to %u and egid to %u: %s\n", +- user, group, strerror(errno)); ++ (unsigned) user, (unsigned) group, strerror(errno)); + return 1; + } + return 0; +@@ -541,7 +541,7 @@ static int createOutputFile(char *fileName, int flags, struct stat *sb, + if ((sb_create.st_uid != sb->st_uid || sb_create.st_gid != sb->st_gid) && + fchown(fd, sb->st_uid, sb->st_gid)) { + message(MESS_ERROR, "error setting owner of %s to uid %u and gid %u: %s\n", +- fileName, sb->st_uid, sb->st_gid, strerror(errno)); ++ fileName, (unsigned) sb->st_uid, (unsigned) sb->st_gid, strerror(errno)); + close(fd); + return -1; + } +@@ -1993,7 +1993,8 @@ static int rotateLogSet(struct logInfo *log, int force) + message(MESS_DEBUG, "%jd bytes ", (intmax_t)log->threshold); + break; + default: +- message(MESS_DEBUG, "rotateLogSet() does not have case for: %u ", log->criterium); ++ message(MESS_DEBUG, "rotateLogSet() does not have case for: %u ", ++ (unsigned) log->criterium); + } + } + +-- +1.8.3.1 + diff --git a/logrotate-3.14.0.tar.xz b/logrotate-3.14.0.tar.xz new file mode 100644 index 0000000..36a7fac Binary files /dev/null and b/logrotate-3.14.0.tar.xz differ diff --git a/logrotate.spec b/logrotate.spec new file mode 100644 index 0000000..066c163 --- /dev/null +++ b/logrotate.spec @@ -0,0 +1,118 @@ +%global _configure ../configure + +Name: logrotate +Version: 3.14.0 +Release: 6 +Summary: simplify the administration of log files +License: GPLv2+ +Url: https://github.com/logrotate/logrotate +Source0: https://github.com/logrotate/logrotate/releases/download/%{version}/logrotate-%{version}.tar.xz +Source1: rwtab +BuildRequires: acl gcc automake git libacl-devel libselinux-devel popt-devel +Requires: coreutils + +# display version information(#1611498) +Patch1: 0001-logrotate-3.14.0-man-version.patch + +# fix Coverity Analysis issue +Patch2: 0002-logrotate-3.14.0-coverity.patch + +Patch6001: do_mkdir-fix-time-of-check-time-of-use-race-conditio.patch +Patch6002: config-logrotate-fix-couple-printf-format-specifiers.patch +Patch6003: explicitly-cast-uid_t-and-gid_t-to-unsigned-int.patch +Patch6004: config-add-variable-initialization-Wconditional-unin.patch + +%description +The logrotate utility is designed to simplify the administration of +log files on a system which generates a lot of log files. Logrotate +allows for the automatic rotation compression, removal and mailing of +log files.logrotate Logrotate can be set to handle a log file daily, weekly, +monthly or when the log file gets to a certain size. + +%package_help + +%prep +%autosetup -n %{name}-%{version} -p1 + +%build +mkdir build && cd build +%configure --with-state-file-path=%{_localstatedir}/lib/logrotate/logrotate.status +%make_build V=1 + +%install +%make_install -C build + +mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d +mkdir -p %{buildroot}%{_sysconfdir}/cron.daily +mkdir -p %{buildroot}%{_localstatedir}/lib/logrotate + +install -p -m 644 examples/logrotate-default %{buildroot}%{_sysconfdir}/logrotate.conf +install -p -m 644 examples/*tmp %{buildroot}%{_sysconfdir}/logrotate.d/ +install -p -m 755 examples/logrotate.cron %{buildroot}%{_sysconfdir}/cron.daily/logrotate + +# logrotate run on read-only root +mkdir -p %{buildroot}%{_sysconfdir}/rwtab.d +install -m644 %{SOURCE1} %{buildroot}%{_sysconfdir}/rwtab.d/logrotate + +%check +%make_build -C build check + +%pre +# create it and copy the /var/lib/logrotate.status in it. +if [ ! -d %{_localstatedir}/lib/logrotate/ -a -f %{_localstatedir}/lib/logrotate.status ]; then + mkdir -p %{_localstatedir}/lib/logrotate + cp -a %{_localstatedir}/lib/logrotate.status %{_localstatedir}/lib/logrotate +fi + +%preun + +%post + +%postun + +%files +%defattr(-,root,root) +%license COPYING +%dir %{_sysconfdir}/cron.daily +%config(noreplace) %{_sysconfdir}/cron.daily/logrotate +%config(noreplace) %{_sysconfdir}/logrotate.conf +%dir %{_sysconfdir}/logrotate.d +%config(noreplace) %{_sysconfdir}/logrotate.d/*tmp +%config(noreplace) %{_sysconfdir}/rwtab.d/logrotate +%{_sbindir}/logrotate +%dir %{_localstatedir}/lib/logrotate +%ghost %verify(not size md5 mtime) %attr(0644, root, root) %{_localstatedir}/lib/logrotate/logrotate.status + +%files help +%defattr(-,root,root) +%doc ChangeLog.md +%{_mandir}/man8/logrotate.8* +%{_mandir}/man5/logrotate.conf.5* + +%changelog +* Fri Sep 27 2019 openEuler Buildteam - 3.14.0-6 +- del unnecessary statement + +* Mon Sep 16 2019 openEuler Buildteam - 3.14.0-5 +- modify spec + +* Tue Sep 10 2019 openEuler Buildteam - 3.14.0-4 +- rewrite spec + +* Tue Aug 20 2019 Shouping Wang - 3.14.0-3 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:format patches for openeuler + +* Mon Aug 19 2019 Shouping Wang - 3.14.0-2 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:format patches + +* Thu Feb 28 2019 Xiaoqi Guo - 3.14.0-1 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:backport patch from https://github.com/logrotate/logrotate/ diff --git a/rwtab b/rwtab new file mode 100644 index 0000000..3210e47 --- /dev/null +++ b/rwtab @@ -0,0 +1 @@ +dirs /var/lib/logrotate