From 293b446a510258a9fe9fbb266d460a99195a01e8 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Sep 14 2022 10:22:39 +0000 Subject: Fix a largish directory walk related memory leak in transactions --- diff --git a/0001-Fix-a-memory-leak-in-the-new-directory-dance-in-ensu.patch b/0001-Fix-a-memory-leak-in-the-new-directory-dance-in-ensu.patch new file mode 100644 index 0000000..5541a04 --- /dev/null +++ b/0001-Fix-a-memory-leak-in-the-new-directory-dance-in-ensu.patch @@ -0,0 +1,38 @@ +From f78be76a00878183da86d5e37ddbe421c5fe028c Mon Sep 17 00:00:00 2001 +Message-Id: +From: Panu Matilainen +Date: Wed, 14 Sep 2022 13:13:24 +0300 +Subject: [PATCH] Fix a memory leak in the new directory dance in ensureDir() + +This would leak the path whenever we already had the directory open. +Which happens a lot. Oops. +--- + lib/fsm.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/lib/fsm.c b/lib/fsm.c +index 129054067..7987abbc9 100644 +--- a/lib/fsm.c ++++ b/lib/fsm.c +@@ -374,8 +374,6 @@ static int fsmDoMkDir(rpmPlugins plugins, int dirfd, const char *dn, + static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create, + int quiet, int *dirfdp) + { +- char *path = xstrdup(p); +- char *dp = path; + char *sp = NULL, *bn; + char *apath = NULL; + int oflags = O_RDONLY; +@@ -387,6 +385,9 @@ static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create, + int dirfd = fsmOpenat(-1, "/", oflags, 1); + int fd = dirfd; /* special case of "/" */ + ++ char *path = xstrdup(p); ++ char *dp = path; ++ + while ((bn = strtok_r(dp, "/", &sp)) != NULL) { + fd = fsmOpenat(dirfd, bn, oflags, 1); + /* assemble absolute path for plugins benefit, sigh */ +-- +2.37.3 + diff --git a/rpm.spec b/rpm.spec index bb0a908..cc80ba5 100644 --- a/rpm.spec +++ b/rpm.spec @@ -30,7 +30,7 @@ %global rpmver 4.18.0 %global snapver rc1 -%global baserelease 3 +%global baserelease 4 %global sover 9 %global srcver %{rpmver}%{?snapver:-%{snapver}} @@ -57,6 +57,7 @@ Patch3: rpm-4.9.90-no-man-dirs.patch # Patches already upstream: Patch100: 0001-Fix-buffer-overrun-from-commit-4420c78beb86cc6739227.patch +Patch101: 0001-Fix-a-memory-leak-in-the-new-directory-dance-in-ensu.patch # These are not yet upstream Patch906: rpm-4.7.1-geode-i686.patch @@ -611,6 +612,9 @@ fi %doc docs/librpm/html/* %changelog +* Wed Sep 14 2022 Panu Matilainen - 4.18.0-0.rc1.4 +- Fix a largish directory walk related memory leak in transactions + * Wed Sep 07 2022 Panu Matilainen - 4.18.0-0.rc1.3 - Fix buffer overrun on rpmdb queries involving ^ in version