Blame SOURCES/0001-logrotate-3.18.0-fix-resource-leaks.patch

d9c745
From 471cf0a6a90e5d45f116f404e1276ea730dbece6 Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Fri, 26 Mar 2021 17:18:09 +0100
d9c745
Subject: [PATCH 1/9] Do not report OOM incorrectly
d9c745
d9c745
In case there is no file in the set to rotate `calloc(0, ...)` is called
d9c745
, which might return NULL.
d9c745
d9c745
Order the check for a zero number of files first, to void calling calloc
d9c745
with a size of zero.
d9c745
d9c745
Upstream-commit: 7b65b267d73970eb59061be907c8c35b4396ada9
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 logrotate.c | 12 ++++++------
d9c745
 1 file changed, 6 insertions(+), 6 deletions(-)
d9c745
d9c745
diff --git a/logrotate.c b/logrotate.c
d9c745
index 507c85a..a8c8480 100644
d9c745
--- a/logrotate.c
d9c745
+++ b/logrotate.c
d9c745
@@ -2212,11 +2212,6 @@ static int rotateLogSet(const struct logInfo *log, int force)
d9c745
     struct logState **state;
d9c745
     struct logNames **rotNames;
d9c745
 
d9c745
-    logHasErrors = calloc(log->numFiles, sizeof(int));
d9c745
-    if (!logHasErrors) {
d9c745
-        message_OOM();
d9c745
-        return 1;
d9c745
-    }
d9c745
     message(MESS_DEBUG, "\nrotating pattern: %s ", log->pattern);
d9c745
     if (force) {
d9c745
         message(MESS_DEBUG, "forced from command line ");
d9c745
@@ -2277,10 +2272,15 @@ static int rotateLogSet(const struct logInfo *log, int force)
d9c745
 
d9c745
     if (log->numFiles == 0) {
d9c745
         message(MESS_DEBUG, "No logs found. Rotation not needed.\n");
d9c745
-        free(logHasErrors);
d9c745
         return 0;
d9c745
     }
d9c745
 
d9c745
+    logHasErrors = calloc(log->numFiles, sizeof(int));
d9c745
+    if (!logHasErrors) {
d9c745
+        message_OOM();
d9c745
+        return 1;
d9c745
+    }
d9c745
+
d9c745
     if (log->flags & LOG_FLAG_SU) {
d9c745
         if (switch_user(log->suUid, log->suGid) != 0) {
d9c745
             free(logHasErrors);
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From 96203f4cdc64e2df3d203231bd1247424a20875e Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Mon, 19 Apr 2021 15:35:37 +0200
d9c745
Subject: [PATCH 2/9] Unify asprintf usage
d9c745
d9c745
Unify the error checking of asprintf(3).
d9c745
d9c745
Also reset the target string pointer to NULL on error, if it is non-
d9c745
local, since the content is undefined according to the specification.
d9c745
d9c745
Also fix potential NULL-pointer usage in sprintf(3):
d9c745
d9c745
logrotate.c:1595:
d9c745
    rotNames->dirName = malloc(strlen(ld) + strlen(log->oldDir) + 2);
d9c745
    sprintf(rotNames->dirName, "%s/%s", ld, log->oldDir);
d9c745
d9c745
Upstream-commit: 5afcdeecc5a3bfe07671a3c05c7a301da9206ccd
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 config.c    | 28 +++++++++++++---------------
d9c745
 logrotate.c |  9 ++++++---
d9c745
 2 files changed, 19 insertions(+), 18 deletions(-)
d9c745
d9c745
diff --git a/config.c b/config.c
d9c745
index df2d90b..19dcfce 100644
d9c745
--- a/config.c
d9c745
+++ b/config.c
d9c745
@@ -815,21 +815,19 @@ int readAllConfigPaths(const char **paths)
d9c745
 
d9c745
 
d9c745
     for (i = 0; i < defTabooCount; i++) {
d9c745
-        int bytes;
d9c745
         char *pattern = NULL;
d9c745
 
d9c745
         /* generate a pattern by concatenating star (wildcard) to the
d9c745
          * suffix literal
d9c745
          */
d9c745
-        bytes = asprintf(&pattern, "*%s", defTabooExts[i]);
d9c745
-        if (bytes != -1) {
d9c745
-            tabooPatterns[i] = pattern;
d9c745
-            tabooCount++;
d9c745
-        } else {
d9c745
+        if (asprintf(&pattern, "*%s", defTabooExts[i]) < 0) {
d9c745
             free_2d_array(tabooPatterns, tabooCount);
d9c745
             message_OOM();
d9c745
             return 1;
d9c745
         }
d9c745
+
d9c745
+        tabooPatterns[i] = pattern;
d9c745
+        tabooCount++;
d9c745
     }
d9c745
 
d9c745
     for (file = paths; *file; file++) {
d9c745
@@ -1421,7 +1419,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
d9c745
                         }
d9c745
 
d9c745
                         while (*endtag) {
d9c745
-                            int bytes;
d9c745
                             char *pattern = NULL;
d9c745
 
d9c745
                             chptr = endtag;
d9c745
@@ -1437,10 +1434,11 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
d9c745
                                     RAISE_ERROR();
d9c745
                                 }
d9c745
                                 tabooPatterns = tmp;
d9c745
-                                bytes = asprintf(&pattern, "*%.*s", (int)(chptr - endtag), endtag);
d9c745
+                                if (asprintf(&pattern, "*%.*s", (int)(chptr - endtag), endtag) < 0) {
d9c745
+                                    message_OOM();
d9c745
+                                    RAISE_ERROR();
d9c745
+                                }
d9c745
 
d9c745
-                                /* should test for malloc() failure */
d9c745
-                                assert(bytes != -1);
d9c745
                                 tabooPatterns[tabooCount] = pattern;
d9c745
                                 tabooCount++;
d9c745
                             }
d9c745
@@ -1481,7 +1479,6 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
d9c745
                         }
d9c745
 
d9c745
                         while (*endtag) {
d9c745
-                            int bytes;
d9c745
                             char *pattern = NULL;
d9c745
                             char **tmp;
d9c745
 
d9c745
@@ -1496,10 +1493,11 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
d9c745
                                 RAISE_ERROR();
d9c745
                             }
d9c745
                             tabooPatterns = tmp;
d9c745
-                            bytes = asprintf(&pattern, "%.*s", (int)(chptr - endtag), endtag);
d9c745
+                            if (asprintf(&pattern, "%.*s", (int)(chptr - endtag), endtag) < 0) {
d9c745
+                                message_OOM();
d9c745
+                                RAISE_ERROR();
d9c745
+                            }
d9c745
 
d9c745
-                            /* should test for malloc() failure */
d9c745
-                            assert(bytes != -1);
d9c745
                             tabooPatterns[tabooCount] = pattern;
d9c745
                             tabooCount++;
d9c745
 
d9c745
@@ -1540,7 +1538,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
d9c745
                                 env_home = pwd->pw_dir;
d9c745
                             }
d9c745
 
d9c745
-                            if (asprintf(&new_key, "%s/%s", env_home, key + 2) == -1) {
d9c745
+                            if (asprintf(&new_key, "%s/%s", env_home, key + 2) < 0) {
d9c745
                                 message_OOM();
d9c745
                                 RAISE_ERROR();
d9c745
                             }
d9c745
diff --git a/logrotate.c b/logrotate.c
d9c745
index a8c8480..e294352 100644
d9c745
--- a/logrotate.c
d9c745
+++ b/logrotate.c
d9c745
@@ -1576,9 +1576,9 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
         ld = dirname(logpath);
d9c745
         if (log->oldDir) {
d9c745
             if (log->oldDir[0] != '/') {
d9c745
-                rotNames->dirName =
d9c745
-                    malloc(strlen(ld) + strlen(log->oldDir) + 2);
d9c745
-                sprintf(rotNames->dirName, "%s/%s", ld, log->oldDir);
d9c745
+                if (asprintf(&rotNames->dirName, "%s/%s", ld, log->oldDir) < 0) {
d9c745
+                    rotNames->dirName = NULL;
d9c745
+                }
d9c745
             } else
d9c745
                 rotNames->dirName = strdup(log->oldDir);
d9c745
         } else
d9c745
@@ -1983,6 +1983,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
         if (asprintf(&(rotNames->finalName), "%s/%s%s%s", rotNames->dirName,
d9c745
                      rotNames->baseName, dext_str, fileext) < 0) {
d9c745
             message_OOM();
d9c745
+            rotNames->finalName = NULL;
d9c745
             return 1;
d9c745
         }
d9c745
         if (asprintf(&destFile, "%s%s", rotNames->finalName, compext) < 0) {
d9c745
@@ -2001,6 +2002,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
         if (asprintf(&(rotNames->finalName), "%s/%s.%d%s", rotNames->dirName,
d9c745
                      rotNames->baseName, logStart, fileext) < 0) {
d9c745
             message_OOM();
d9c745
+            rotNames->finalName = NULL;
d9c745
         }
d9c745
     }
d9c745
 
d9c745
@@ -2084,6 +2086,7 @@ static int rotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
                 free(rotNames->disposeName);
d9c745
                 if (asprintf(&rotNames->disposeName, "%s%s", rotNames->finalName, ext) < 0) {
d9c745
                     message_OOM();
d9c745
+                    rotNames->disposeName = NULL;
d9c745
                     return 1;
d9c745
                 }
d9c745
 
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From 3cf921e0d58993b064cd6d52b44835008345f498 Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Mon, 19 Apr 2021 15:40:19 +0200
d9c745
Subject: [PATCH 3/9] Update custom asprintf implementation
d9c745
d9c745
Check for vsnprintf(3) failures.
d9c745
d9c745
Silence conversion warnings.
d9c745
d9c745
Do not call exit(2) on allocation failure, but return -1 like the
d9c745
specification says. All callers check the return value, since they
d9c745
need to handle standard asprintf(3) implementations.
d9c745
d9c745
Upstream-commit: f917b31dbb47992bf5c5342c7312ddb2e64efc40
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 config.c | 20 ++++++++------------
d9c745
 1 file changed, 8 insertions(+), 12 deletions(-)
d9c745
d9c745
diff --git a/config.c b/config.c
d9c745
index 19dcfce..0d79980 100644
d9c745
--- a/config.c
d9c745
+++ b/config.c
d9c745
@@ -61,24 +61,20 @@ int asprintf(char **string_ptr, const char *format, ...)
d9c745
 
d9c745
     va_start(arg, format);
d9c745
     size = vsnprintf(NULL, 0, format, arg);
d9c745
-    size++;
d9c745
     va_end(arg);
d9c745
-    va_start(arg, format);
d9c745
-    str = malloc(size);
d9c745
+    if (size < 0) {
d9c745
+        return -1;
d9c745
+    }
d9c745
+    str = malloc((size_t)size + 1);
d9c745
     if (str == NULL) {
d9c745
-        va_end(arg);
d9c745
-        /*
d9c745
-         * Strictly speaking, GNU asprintf doesn't do this,
d9c745
-         * but the caller isn't checking the return value.
d9c745
-         */
d9c745
-        message_OOM();
d9c745
-        exit(1);
d9c745
+        return -1;
d9c745
     }
d9c745
-    rv = vsnprintf(str, size, format, arg);
d9c745
+    va_start(arg, format);
d9c745
+    rv = vsnprintf(str, (size_t)size + 1, format, arg);
d9c745
     va_end(arg);
d9c745
 
d9c745
     *string_ptr = str;
d9c745
-    return (rv);
d9c745
+    return rv;
d9c745
 }
d9c745
 
d9c745
 #endif
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From ace9818a606a0c96bb6e4da479ed151650b8fa3a Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Mon, 19 Apr 2021 15:45:55 +0200
d9c745
Subject: [PATCH 4/9] Use asprintf instead of split malloc + sprintf
d9c745
d9c745
Use asprintf(3) instead of split usage of malloc(3) and sprintf(3) to
d9c745
reduce the chance of potential size inconsistencies.
d9c745
d9c745
Upstream-commit: 001352baa924f021748513b6d09d37eca754d5cc
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 config.c    |  5 ++---
d9c745
 logrotate.c | 25 ++++++++++++-------------
d9c745
 2 files changed, 14 insertions(+), 16 deletions(-)
d9c745
d9c745
diff --git a/config.c b/config.c
d9c745
index 0d79980..2905ff7 100644
d9c745
--- a/config.c
d9c745
+++ b/config.c
d9c745
@@ -1886,13 +1886,12 @@ duperror:
d9c745
                                     continue;
d9c745
                                 }
d9c745
                             }
d9c745
-                            ld = malloc(strlen(dirName) + strlen(newlog->oldDir) + 2);
d9c745
-                            if (ld == NULL) {
d9c745
+                            if (asprintf(&ld, "%s/%s", dirName, newlog->oldDir) < 0) {
d9c745
                                 message_OOM();
d9c745
                                 free(dirpath);
d9c745
                                 goto error;
d9c745
                             }
d9c745
-                            sprintf(ld, "%s/%s", dirName, newlog->oldDir);
d9c745
+
d9c745
                             free(dirpath);
d9c745
 
d9c745
                             if (newlog->oldDir[0] != '/') {
d9c745
diff --git a/logrotate.c b/logrotate.c
d9c745
index e294352..a72329e 100644
d9c745
--- a/logrotate.c
d9c745
+++ b/logrotate.c
d9c745
@@ -1810,15 +1810,6 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
         }
d9c745
     }
d9c745
 
d9c745
-    /* adding 2 due to / and \0 being added by snprintf */
d9c745
-    rotNames->firstRotated =
d9c745
-        malloc(strlen(rotNames->dirName) + strlen(rotNames->baseName) +
d9c745
-                strlen(fileext) + strlen(compext) + DATEEXT_LEN + 2 );
d9c745
-    if (rotNames->firstRotated == NULL) {
d9c745
-        message_OOM();
d9c745
-        return 1;
d9c745
-    }
d9c745
-
d9c745
     if (log->flags & LOG_FLAG_DATEEXT) {
d9c745
         /* glob for compressed files with our pattern
d9c745
          * and compress ext */
d9c745
@@ -1882,9 +1873,13 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
             rotNames->disposeName = NULL;
d9c745
         }
d9c745
         /* firstRotated is most recently created/compressed rotated log */
d9c745
-        sprintf(rotNames->firstRotated, "%s/%s%s%s%s",
d9c745
+        if (asprintf(&rotNames->firstRotated, "%s/%s%s%s%s",
d9c745
                 rotNames->dirName, rotNames->baseName, dext_str, fileext,
d9c745
-                (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
d9c745
+                (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext) < 0) {
d9c745
+            message_OOM();
d9c745
+            rotNames->firstRotated = NULL;
d9c745
+            return 1;
d9c745
+        }
d9c745
         globfree(&globResult);
d9c745
         free(glob_pattern);
d9c745
     } else {
d9c745
@@ -1915,9 +1910,13 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
             }
d9c745
         }
d9c745
 
d9c745
-        sprintf(rotNames->firstRotated, "%s/%s.%d%s%s", rotNames->dirName,
d9c745
+        if (asprintf(&rotNames->firstRotated, "%s/%s.%d%s%s", rotNames->dirName,
d9c745
                 rotNames->baseName, logStart, fileext,
d9c745
-                (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext);
d9c745
+                (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext) < 0) {
d9c745
+            message_OOM();
d9c745
+            rotNames->firstRotated = NULL;
d9c745
+            return 1;
d9c745
+        }
d9c745
 
d9c745
         for (i = rotateCount + logStart - 1; (i >= 0) && !hasErrors; i--) {
d9c745
             free(newName);
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From e8a655ef1977add152d79c4dc8148fe7b1c9bca2 Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Mon, 19 Apr 2021 17:52:48 +0200
d9c745
Subject: [PATCH 5/9] Mark read-only string variable const
d9c745
d9c745
Prevent it accidentally being passed to free(3) or similar.
d9c745
d9c745
Upstream-commit: 2231aba823ff6e5a18d996e81ef63df0871224dd
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 logrotate.c | 2 +-
d9c745
 1 file changed, 1 insertion(+), 1 deletion(-)
d9c745
d9c745
diff --git a/logrotate.c b/logrotate.c
d9c745
index a72329e..7d49261 100644
d9c745
--- a/logrotate.c
d9c745
+++ b/logrotate.c
d9c745
@@ -1567,7 +1567,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
     state->lastRotated = now;
d9c745
 
d9c745
     {
d9c745
-        char *ld;
d9c745
+        const char *ld;
d9c745
         char *logpath = strdup(log->files[logNum]);
d9c745
         if (logpath == NULL) {
d9c745
             message_OOM();
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From c06f20f781c74b2256e8f1757433db7e043b4ddf Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Mon, 19 Apr 2021 17:59:21 +0200
d9c745
Subject: [PATCH 6/9] Limit scope of variable
d9c745
d9c745
Limit the scope of a variable, by splitting it into several distinct
d9c745
block scope variables.
d9c745
d9c745
This makes some asprintf(3) calls obsolete, and improves readability by
d9c745
splitting the purpose of the variable.
d9c745
d9c745
Upstream-commit: b37fb75f569b3ddde30dd85184ea160f63abb7d5
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 logrotate.c | 19 ++++++++-----------
d9c745
 1 file changed, 8 insertions(+), 11 deletions(-)
d9c745
d9c745
diff --git a/logrotate.c b/logrotate.c
d9c745
index 7d49261..962ac55 100644
d9c745
--- a/logrotate.c
d9c745
+++ b/logrotate.c
d9c745
@@ -1529,7 +1529,6 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
                               struct logState *state, struct logNames *rotNames)
d9c745
 {
d9c745
     struct tm now;
d9c745
-    char *oldName = NULL;
d9c745
     const char *compext = "";
d9c745
     const char *fileext = "";
d9c745
     int hasErrors = 0;
d9c745
@@ -1770,11 +1769,8 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
                 sortGlobResult(&globResult, strlen(rotNames->dirName) + 1 + strlen(rotNames->baseName), dformat);
d9c745
                 for (glob_count = 0; glob_count < globResult.gl_pathc && !hasErrors; glob_count++) {
d9c745
                     struct stat sbprev;
d9c745
+                    const char *oldName = globResult.gl_pathv[glob_count];
d9c745
 
d9c745
-                    if (asprintf(&oldName, "%s", (globResult.gl_pathv)[glob_count]) < 0) {
d9c745
-                        message_OOM();
d9c745
-                        return 1;
d9c745
-                    }
d9c745
                     if (stat(oldName, &sbprev)) {
d9c745
                         if (errno == ENOENT)
d9c745
                             message(MESS_DEBUG, "previous log %s does not exist\n", oldName);
d9c745
@@ -1783,7 +1779,6 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
                     } else {
d9c745
                         hasErrors = compressLogFile(oldName, log, &sbprev);
d9c745
                     }
d9c745
-                    free(oldName);
d9c745
                 }
d9c745
             } else {
d9c745
                 message(MESS_DEBUG,
d9c745
@@ -1793,6 +1788,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
             free(glob_pattern);
d9c745
         } else {
d9c745
             struct stat sbprev;
d9c745
+            char *oldName;
d9c745
             if (asprintf(&oldName, "%s/%s.%d%s", rotNames->dirName,
d9c745
                          rotNames->baseName, logStart, fileext) < 0) {
d9c745
                 message_OOM();
d9c745
@@ -1853,16 +1849,14 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
             }
d9c745
             if (mail_out != (size_t)-1) {
d9c745
                 /* oldName is oldest Backup found (for unlink later) */
d9c745
-                if (asprintf(&oldName, "%s", (globResult.gl_pathv)[mail_out]) < 0) {
d9c745
-                    message_OOM();
d9c745
-                    return 1;
d9c745
-                }
d9c745
+                const char *oldName = globResult.gl_pathv[mail_out];
d9c745
                 rotNames->disposeName = strdup(oldName);
d9c745
                 if (rotNames->disposeName == NULL) {
d9c745
                     message_OOM();
d9c745
+                    globfree(&globResult);
d9c745
+                    free(glob_pattern);
d9c745
                     return 1;
d9c745
                 }
d9c745
-                free(oldName);
d9c745
             } else {
d9c745
                 free(rotNames->disposeName);
d9c745
                 rotNames->disposeName = NULL;
d9c745
@@ -1878,6 +1872,8 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
                 (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext) < 0) {
d9c745
             message_OOM();
d9c745
             rotNames->firstRotated = NULL;
d9c745
+            globfree(&globResult);
d9c745
+            free(glob_pattern);
d9c745
             return 1;
d9c745
         }
d9c745
         globfree(&globResult);
d9c745
@@ -1885,6 +1881,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
     } else {
d9c745
         int i;
d9c745
         char *newName = NULL;
d9c745
+        char *oldName;
d9c745
 
d9c745
         if (rotateCount == -1) {
d9c745
             rotateCount = findLastRotated(rotNames, fileext, compext);
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From 1a1eb69e6c4ae403edceb411cb0bbc80473e2527 Mon Sep 17 00:00:00 2001
d9c745
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
d9c745
Date: Tue, 20 Apr 2021 17:41:16 +0200
d9c745
Subject: [PATCH 7/9] Free memory on noolddir configuration
d9c745
d9c745
Consider the following configuration:
d9c745
    olddir /var/log/foo
d9c745
    noolddir
d9c745
d9c745
Do not leak the memory of the initial olddir path.
d9c745
d9c745
Upstream-commit: 59e8e321d3221a3beaf7b9c99b17d5cb7dbcfaf0
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 config.c | 2 +-
d9c745
 1 file changed, 1 insertion(+), 1 deletion(-)
d9c745
d9c745
diff --git a/config.c b/config.c
d9c745
index 2905ff7..b7406f5 100644
d9c745
--- a/config.c
d9c745
+++ b/config.c
d9c745
@@ -1134,7 +1134,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
d9c745
                         if (newlog->dateformat == NULL)
d9c745
                             continue;
d9c745
                     } else if (!strcmp(key, "noolddir")) {
d9c745
-                        newlog->oldDir = NULL;
d9c745
+                        freeLogItem(oldDir);
d9c745
                     } else if (!strcmp(key, "mailfirst")) {
d9c745
                         newlog->flags |= LOG_FLAG_MAILFIRST;
d9c745
                     } else if (!strcmp(key, "maillast")) {
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From 4aabfd0fe19832ba1df8919356d1d2d4b463937d Mon Sep 17 00:00:00 2001
d9c745
From: Kamil Dudka <kdudka@redhat.com>
d9c745
Date: Mon, 3 May 2021 15:14:09 +0200
d9c745
Subject: [PATCH 8/9] readConfigFile: release `globerr_msg` on all code paths
d9c745
d9c745
This eliminates the following reports by Coverity:
d9c745
d9c745
Error: RESOURCE_LEAK (CWE-772):
d9c745
logrotate-3.18.0.18_7a4d/config.c:1798: alloc_arg: "asprintf" allocates memory that is stored into "globerr_msg". [Note: The source code implementation of the function has been overridden by a builtin model.]
d9c745
logrotate-3.18.0.18_7a4d/config.c:2116: leaked_storage: Variable "globerr_msg" going out of scope leaks the storage it points to.
d9c745
d9c745
Error: RESOURCE_LEAK (CWE-772):
d9c745
logrotate-3.18.0.18_7a4d/config.c:1798: alloc_arg: "asprintf" allocates memory that is stored into "globerr_msg". [Note: The source code implementation of the function has been overridden by a builtin model.]
d9c745
logrotate-3.18.0.18_7a4d/config.c:2122: leaked_storage: Variable "globerr_msg" going out of scope leaks the storage it points to.
d9c745
d9c745
Closes: https://github.com/logrotate/logrotate/pull/387
d9c745
d9c745
Upstream-commit: 97f841be2bb52b9ac00cd564a6eb0a853d1017bd
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 config.c | 2 ++
d9c745
 1 file changed, 2 insertions(+)
d9c745
d9c745
diff --git a/config.c b/config.c
d9c745
index b7406f5..91fd412 100644
d9c745
--- a/config.c
d9c745
+++ b/config.c
d9c745
@@ -2086,12 +2086,14 @@ next_state: ;
d9c745
 
d9c745
     munmap(buf, length);
d9c745
     close(fd);
d9c745
+    free(globerr_msg);
d9c745
     return logerror;
d9c745
 error:
d9c745
     /* free is a NULL-safe operation */
d9c745
     free(key);
d9c745
     munmap(buf, length);
d9c745
     close(fd);
d9c745
+    free(globerr_msg);
d9c745
     return 1;
d9c745
 }
d9c745
 
d9c745
-- 
d9c745
2.30.2
d9c745
d9c745
d9c745
From b5610cd1b0bc2cf9ab887007a953fbf6340cb150 Mon Sep 17 00:00:00 2001
d9c745
From: Kamil Dudka <kdudka@redhat.com>
d9c745
Date: Mon, 3 May 2021 15:17:59 +0200
d9c745
Subject: [PATCH 9/9] prerotateSingleLog: release `oldName` on all code paths
d9c745
d9c745
This eliminates the following reports by Coverity:
d9c745
d9c745
Error: RESOURCE_LEAK (CWE-772):
d9c745
logrotate-3.18.0.18_7a4d/logrotate.c:1911: alloc_arg: "asprintf" allocates memory that is stored into "oldName". [Note: The source code implementation of the function has been overridden by a builtin model.]
d9c745
logrotate-3.18.0.18_7a4d/logrotate.c:1919: noescape: Resource "oldName" is not freed or pointed-to in "strdup".
d9c745
logrotate-3.18.0.18_7a4d/logrotate.c:1922: leaked_storage: Variable "oldName" going out of scope leaks the storage it points to.
d9c745
d9c745
Error: RESOURCE_LEAK (CWE-772):
d9c745
logrotate-3.18.0.18_7a4d/logrotate.c:1911: alloc_arg: "asprintf" allocates memory that is stored into "oldName". [Note: The source code implementation of the function has been overridden by a builtin model.]
d9c745
logrotate-3.18.0.18_7a4d/logrotate.c:1919: noescape: Resource "oldName" is not freed or pointed-to in "strdup".
d9c745
logrotate-3.18.0.18_7a4d/logrotate.c:1931: leaked_storage: Variable "oldName" going out of scope leaks the storage it points to.
d9c745
d9c745
Closes: https://github.com/logrotate/logrotate/pull/387
d9c745
d9c745
Upstream-commit: 85bc130b19344a3d9c8b472142df14ddcd0a166d
d9c745
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d9c745
---
d9c745
 logrotate.c | 2 ++
d9c745
 1 file changed, 2 insertions(+)
d9c745
d9c745
diff --git a/logrotate.c b/logrotate.c
d9c745
index 962ac55..d3f2825 100644
d9c745
--- a/logrotate.c
d9c745
+++ b/logrotate.c
d9c745
@@ -1903,6 +1903,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
             rotNames->disposeName = strdup(oldName);
d9c745
             if (rotNames->disposeName == NULL) {
d9c745
                 message_OOM();
d9c745
+                free(oldName);
d9c745
                 return 1;
d9c745
             }
d9c745
         }
d9c745
@@ -1911,6 +1912,7 @@ static int prerotateSingleLog(const struct logInfo *log, unsigned logNum,
d9c745
                 rotNames->baseName, logStart, fileext,
d9c745
                 (log->flags & LOG_FLAG_DELAYCOMPRESS) ? "" : compext) < 0) {
d9c745
             message_OOM();
d9c745
+            free(oldName);
d9c745
             rotNames->firstRotated = NULL;
d9c745
             return 1;
d9c745
         }
d9c745
-- 
d9c745
2.30.2
d9c745