From b8db4331eae231eb5e1ab95f664a53a8e4360d89 Mon Sep 17 00:00:00 2001 From: kouwenqi Date: Tue, 30 Apr 2024 09:44:40 +0800 Subject: [PATCH] Pass the correct stat to backup files --- ...ass-the-correct-stat-to-backup-files.patch | 62 +++++++++++++++++++ patch.spec | 6 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 backport-Pass-the-correct-stat-to-backup-files.patch diff --git a/backport-Pass-the-correct-stat-to-backup-files.patch b/backport-Pass-the-correct-stat-to-backup-files.patch new file mode 100644 index 0000000..fdf316e --- /dev/null +++ b/backport-Pass-the-correct-stat-to-backup-files.patch @@ -0,0 +1,62 @@ +From c835ecc67b7e37c0d0b7dd7e032209fdaa285808 Mon Sep 17 00:00:00 2001 +From: Takashi Iwai +Date: Wed, 6 Apr 2022 10:48:35 +0200 +Subject: [PATCH] Pass the correct stat to backup files + +The last case to call output_file() in the main loop is + output_file (outname, NULL, &tmpoutst, NULL, NULL, + file_type | 0, backup); +and this essentially means to create a backup file (where to=NULL) +only if backup=true, and does nothing else. + +And, in the current code, the passed file stat (&tmpoutst) is a file +stat of the temporary file that has been processed, not the original +file (outname) to be backed up. When the backup is performed +immediately, this is no big problem. However, output_file() may +schedule the deferred handling, and the given file may be backed up at +a later point. The problem is that create_backup() tries to avoid the +backup of the same file twice, and it checks the given stat i-node +number in the hash list. Since it's a stat of a temporary file, the +same i-node number may be reused once a temp file is deleted and +another is created. This results in a false-positive detection of the +already existing file, eventually missing a backup file. + +This patch attempts to address the issue: +- Modify the condition for better understanding, clearly indicating + that the code there is for creating a backup file +- Pass the stat of the original file instead of a temporary file + +BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1198106 +Signed-off-by: Takashi Iwai +Signed-off-by: Jean Delvare +--- + src/patch.c | 13 ++++++++++--- + 1 file changed, 10 insertions(+), 3 deletions(-) + +diff --git a/src/patch.c b/src/patch.c +index 9684794..5a61241 100644 +--- a/src/patch.c ++++ b/src/patch.c +@@ -622,9 +622,16 @@ main (int argc, char **argv) + output_file (NULL, NULL, NULL, inname, &instat, + mode, backup); + } +- else +- output_file (outname, NULL, &tmpoutst, NULL, NULL, +- file_type | 0, backup); ++ else if (backup) ++ { ++ struct stat outstat; ++ ++ if (stat_file (outname, &outstat, NULL) != 0) ++ say ("Cannot stat file %s, skipping backup\n", outname); ++ else ++ output_file (outname, NULL, &outstat, NULL, NULL, ++ file_type | 0, true); ++ } + } + } + } +-- +2.23.0 + diff --git a/patch.spec b/patch.spec index a85374e..00028de 100644 --- a/patch.spec +++ b/patch.spec @@ -1,6 +1,6 @@ Name: patch Version: 2.7.6 -Release: 20 +Release: 21 Summary: Utiliity which applies a patch file to original files. License: GPLv3+ URL: http://www.gnu.org/software/patch/patch.html @@ -27,6 +27,7 @@ Patch18: backport-Avoid-invalid-memory-access-in-context-format-diffs.pat Patch19: backport-Fix-failed-assertion-outstate-after_newline.patch Patch20: backport-Add-missing-section-tests-to-context-format-test-cas.patch Patch21: backport-Fix-test-for-presence-of-BASH_LINENO-0.patch +Patch22: backport-Pass-the-correct-stat-to-backup-files.patch BuildRequires: gcc libselinux-devel libattr-devel ed Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-root @@ -69,6 +70,9 @@ CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" %{_mandir}/man1/* %changelog +* Mon Apr 29 2024 kouwenqi - 2.7.6-21 +- Pass the correct stat to backup files + * Fri Dec 30 2022 Xibo.Wang - 2.7.6-20 - Skip "ed" test when the ed utility is not installed - Abort when cleaning up fails