arrfab / rpms / libreport

Forked from rpms/libreport 5 years ago
Clone

Blame SOURCES/0020-lib-dump_dir-Clean-up-on-failure-in-dd_delete.patch

4188e0
From 69c83b933da2ac7c4a1450c5882027030eb79022 Mon Sep 17 00:00:00 2001
4188e0
From: Ernestas Kulik <ekulik@redhat.com>
4188e0
Date: Tue, 12 Mar 2019 13:30:12 +0100
4188e0
Subject: [PATCH] lib: dump_dir: Clean up on failure in dd_delete()
4188e0
4188e0
All callers assume that dd_delete() will succeed and the dump directory
4188e0
struct will be freed, but in some cases that does not happen and leaks
4188e0
occur.
4188e0
4188e0
Resolves rhbz#1671233
4188e0
4188e0
Signed-off-by: Ernestas Kulik <ekulik@redhat.com>
4188e0
---
4188e0
 src/lib/dump_dir.c | 26 +++++++++++++++++++++-----
4188e0
 1 file changed, 21 insertions(+), 5 deletions(-)
4188e0
4188e0
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
4188e0
index 632a01fa..4533f4c1 100644
4188e0
--- a/src/lib/dump_dir.c
4188e0
+++ b/src/lib/dump_dir.c
4188e0
@@ -1555,19 +1555,33 @@ static int dd_delete_meta_data(struct dump_dir *dd)
4188e0
 
4188e0
 int dd_delete(struct dump_dir *dd)
4188e0
 {
4188e0
+    int retval;
4188e0
+
4188e0
+    retval = 0;
4188e0
+
4188e0
     if (!dd->locked)
4188e0
     {
4188e0
         error_msg("unlocked problem directory %s cannot be deleted", dd->dd_dirname);
4188e0
-        return -1;
4188e0
+
4188e0
+        retval = -1;
4188e0
+
4188e0
+        goto close;
4188e0
     }
4188e0
 
4188e0
     if (dd_delete_meta_data(dd) != 0)
4188e0
-        return -2;
4188e0
+    {
4188e0
+        retval = -2;
4188e0
+
4188e0
+        goto close;
4188e0
+    }
4188e0
 
4188e0
     if (delete_file_dir(dd->dd_fd, /*skip_lock_file:*/ true) != 0)
4188e0
     {
4188e0
         perror_msg("Can't remove contents of directory '%s'", dd->dd_dirname);
4188e0
-        return -2;
4188e0
+
4188e0
+        retval = -2;
4188e0
+
4188e0
+        goto close;
4188e0
     }
4188e0
 
4188e0
     unsigned cnt = RMDIR_FAIL_COUNT;
4188e0
@@ -1586,12 +1600,14 @@ int dd_delete(struct dump_dir *dd)
4188e0
     if (cnt == 0)
4188e0
     {
4188e0
         perror_msg("Can't remove directory '%s'", dd->dd_dirname);
4188e0
-        return -3;
4188e0
+
4188e0
+        retval = -3;
4188e0
     }
4188e0
 
4188e0
     dd->locked = 0; /* delete_file_dir already removed .lock */
4188e0
+close:
4188e0
     dd_close(dd);
4188e0
-    return 0;
4188e0
+    return retval;
4188e0
 }
4188e0
 
4188e0
 int dd_chown(struct dump_dir *dd, uid_t new_uid)
4188e0
-- 
4188e0
2.21.0
4188e0