summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Pass the correct stat to backup filesHEADmasterTakashi Iwai2022-05-101-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <tiwai@suse.de> Signed-off-by: Jean Delvare <jdelvare@suse.de>
* maint: modernize README-{hacking,prereq}Paul Eggert2021-10-302-38/+87
|
* Fix test for presence of BASH_LINENO[0]Kerin Millar2021-01-081-1/+1
| | | | | | | | | | | eval is not some sort of magical sandbox for executing code that might cause the shell's parser to take exception. Render the test resilient by carrying it out within a subshell. While at it, position the redirection so that STDERR is, in fact, muted. Signed-off-by: Kerin Millar <kfm@plushkava.net> Reported-by: Paolo Pedroni <paolo.pedroni@iol.it> Closes: https://bugs.gentoo.org/738810
* gnulib: update to latestAndreas Gruenbacher2020-05-146-141/+190
| | | | | | | | | | * bootstrap: Update. * bootstrap.conf (gnulib_modules): Replace getdate with parse-datetime, malloc with malloc-gnu, and realloc with realloc-gnu. * src/patch.c (main): Function find_backup_file_name has gained a new dir_fd argument. * src/util.c (create_backup): Likewise. (fetchname): Function get_date has been renamed to parse_datetime.
* Add missing-section tests to context-format test caseAndreas Gruenbacher2019-12-241-2/+84
| | | | | | * tests/context-format: Add tests with a missing pattern and a missing replacement section in a hunk. Patch should fill in the missing sections from the existing sections.
* Fix failed assertion 'outstate->after_newline'Andreas Gruenbacher2019-07-161-0/+7
| | | | | | | The assertion triggers when the -o FILE option is used, more than one output file is written into FILE, and one of those files (except the last one) ends in the middle of a line. * src/patch.c (main): Fix the case described above.
* Avoid invalid memory access in context format diffsAndreas Gruenbacher2019-07-151-0/+1
| | | | | * src/pch.c (another_hunk): Avoid invalid memory access in context format diffs.
* Don't follow symlinks unless --follow-symlinks is givenAndreas Gruenbacher2019-07-152-5/+21
| | | | | | | | | * src/inp.c (plan_a, plan_b), src/util.c (copy_to_fd, copy_file, append_to_file): Unless the --follow-symlinks option is given, open files with the O_NOFOLLOW flag to avoid following symlinks. So far, we were only doing that consistently for input files. * src/util.c (create_backup): When creating empty backup files, (re)create them with O_CREAT | O_EXCL to avoid following symlinks in that case as well.
* Don't crash when RLIMIT_NOFILE is set to RLIM_INFINITYAndreas Gruenbacher2019-06-281-13/+23
| | | | | | | | | | | | * src/safe.c (min_cached_fds): Define minimum number of cached dir file descriptors. (max_cached_fds): Change type to rlim_t to allow storing RLIM_INFINITY. (init_dirfd_cache): Set max_cached_fds to RLIM_INFINITY when RLIMIT_NOFILE is RLIM_INFINITY. Set the initial hash table size to min_cached_fds, independent of RLIMIT_NOFILE: patches commonly only affect one or a few files, so a small hash table will usually suffice; if needed, the hash table will grow. (insert_cached_dirfd): Don't shrink the cache when max_cached_fds is RLIM_INFINITY.
* Abort when cleaning up failsAndreas Gruenbacher2019-06-281-2/+6
| | | | | | | | | When a fatal error triggers during cleanup, another attempt will be made to clean up, which will likely lead to the same fatal error. So instead, bail out when that happens. src/patch.c (cleanup): Bail out when called recursively. (main): There is no need to call output_files() before cleanup() as cleanup() already does that.
* Skip "ed" test when the ed utility is not installedAndreas Gruenbacher2019-06-271-0/+1
| | | | * tests/ed-style: Require ed.
* Improve support for memory leak detectionAndreas Gruenbacher2019-06-271-1/+15
| | | | | | | When building with the address sanitizer on, free some more resources before exiting. (This is unnecessary when not looking for memory leaks.) * src/patch.c (init_files_to_delete): Add dispose function for freeing filenames.
* Fix swapping fake lines in pch_swapAndreas Gruenbacher2018-08-171-1/+1
| | | | | | | | * src/pch.c (pch_swap): Fix swapping p_bfake and p_efake when there is a blank line in the middle of a context-diff hunk: that empty line stays in the middle of the hunk and isn't swapped. Fixes: https://savannah.gnu.org/bugs/index.php?53133
* Make the (debug & 2) output more usefulAndreas Gruenbacher2018-08-171-3/+9
| | | | | | * src/pch.c (another_hunk): In the (debug & 2) output, fix how empty lines that are not part of the patch context are printed. Also, add newlines to lines that are missing them to keep the output readable.
* Don't leak temporary file on failed multi-file ed-style patchJean Delvare2018-05-072-0/+32
| | | | | | | | | | | | | | | | The previous fix worked fine with single-file ed-style patches, but would still leak temporary files in the case of multi-file ed-style patch. Fix that case as well, and extend the test case to check for it. * src/patch.c (main): Unlink TMPEDNAME if needed before moving to the next file in a patch. This closes bug #53820: https://savannah.gnu.org/bugs/index.php?53820 Fixes: 123eaff0d5d1 ("Fix arbitrary command execution in ed-style patches (CVE-2018-1000156)") Fixes: 19599883ffb6 ("Don't leak temporary file on failed ed-style patch")
* Don't leak temporary file on failed ed-style patchJean Delvare2018-05-033-6/+8
| | | | | | | | | | | | | | | | Now that we write ed-style patches to a temporary file before we apply them, we need to ensure that the temporary file is removed before we leave, even on fatal error. * src/pch.c (do_ed_script): Use global TMPEDNAME instead of local tmpname. Don't unlink the file directly, instead tag it for removal at exit time. * src/patch.c (cleanup): Unlink TMPEDNAME at exit. This closes bug #53820: https://savannah.gnu.org/bugs/index.php?53820 Fixes: 123eaff0d5d1 ("Fix arbitrary command execution in ed-style patches (CVE-2018-1000156)")
* Request 'alloca' module from gnulib.Bruno Haible2018-04-071-1/+2
| | | | * bootstrap.conf (gnulib_modules): Add 'alloca'.
* Fix 'ed-style' test failure.Bruno Haible2018-04-071-2/+1
| | | | * tests/ed-style: Remove '?' line from expected output.
* Fix check of return value of fwrite().Bruno Haible2018-04-072-7/+11
| | | | | * src/patch.c (copy_till): Consider incomplete fwrite() write as an error. * src/pch.c (pch_write_line, do_ed_script): Likewise.
* maint: avoid warnings from GCC8Jim Meyering2018-04-073-5/+12
| | | | | | | | | | | | | | | | | | | | Hi Andreas, I configured with --enable-gcc-warnings and bleeding-edge gcc (version 8.0.1 20180406) and hit some warning-escalated-to-errors. This fixes them: >From a71ddb200dbe7ac0f9258796b5a51979b2740e88 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@fb.com> Date: Fri, 6 Apr 2018 16:47:00 -0700 Subject: [PATCH] maint: avoid warnings from GCC8 * src/common.h (FALLTHROUGH): Define. * src/patch.c (abort_hunk_context): Use FALLTHROUGH macro in place of a comment. This avoids a warning from -Wimplicit-fallthrough=. * src/pch.c (do_ed_script): Add otherwise unnecessary initialization to avoid warning from -Wmaybe-uninitialized. (another_hunk): Use FALLTHROUGH macro here, too, twice.
* Minor cleanups in do_ed_scriptAndreas Gruenbacher2018-04-061-30/+27
| | | | * src/pch.c (do_ed_script): Minor cleanups.
* Use gnulib execute moduleAndreas Gruenbacher2018-04-063-19/+35
| | | | | * bootstrap.conf (gnulib_modules): Add execute. * src/pch.c (do_ed_script): Switch from fork + execlp to execute.
* Invoke ed directly instead of using the shellAndreas Gruenbacher2018-04-061-4/+2
| | | | | * src/pch.c (do_ed_script): Invoke ed directly instead of using a shell command to avoid quoting vulnerabilities.
* Fix arbitrary command execution in ed-style patches (CVE-2018-1000156)Andreas Gruenbacher2018-04-063-25/+108
| | | | | | | | * src/pch.c (do_ed_script): Write ed script to a temporary file instead of piping it to ed: this will cause ed to abort on invalid commands instead of rejecting them and carrying on. * tests/ed-style: New test case. * tests/Makefile.am (TESTS): Add test case.
* Allow input files to be missing for ed-style patchesAndreas Gruenbacher2018-04-061-3/+5
| | | | | * src/pch.c (do_ed_script): Allow input files to be missing so that new files will be created as with non-ed-style patches.
* Fix segfault with mangled rename patchAndreas Gruenbacher2018-02-121-1/+2
| | | | | | http://savannah.gnu.org/bugs/?53132 * src/pch.c (intuit_diff_type): Ensure that two filenames are specified for renames and copies (fix the existing check).
* Test suite: fix Korn shell incompatibilityAndreas Gruenbacher2018-02-071-1/+1
| | | | tests/merge: In a Korn shell, shift apparently fails when $# is 0.
* Test suite compatibility fixesAndreas Gruenbacher2018-02-074-27/+18
| | | | | | | * tests/crlf-handling, tests/git-cleanup, tests/test-lib.sh: Use printf instead of echo -e / echo -n for compatibility with systems that don't support these echo options. * tests/merge: Minor other cleanups.
* Avoid set_file_attributes sign conversion warningsAndreas Gruenbacher2018-02-071-2/+2
| | | | | * src/util.c (set_file_attributes): Avoid sign conversion warnings when assigning -1 to uid_t / gid_t.
* Version 2.7.6v2.7.6Andreas Gruenbacher2018-02-031-0/+7
| | | | * NEWS: Update.
* Fix typo in READMEAndreas Gruenbacher2018-02-031-1/+1
| | | | * README: Fix typo.
* Switch to gnupload moduleAndreas Gruenbacher2018-02-032-11/+3
| | | | | | * bootstrap.conf: use gnupload module. * (RELEASE_TYPE): Define, as maint.mk expects it to be defined. (tell-upload): Remove obsolete target.
* Remove stale reference to m4/utimbuf.m4Andreas Gruenbacher2018-02-031-1/+0
| | | | * Makefile.am (EXTRA_DIST): Remove stale reference to m4/utimbuf.m4.
* maint: update bootstrap and gnulib submoduleAndreas Gruenbacher2018-02-032-100/+152
| | | | * bootstrap: Update from gnulib.
* Clarify the error messages for malformed normal diff patchesAndreas Gruenbacher2018-01-231-2/+2
| | | | | * src/pch.c (another_hunk): Clarify the error messages for malformed normal diff patches.
* Create git diff files with indicated modeThomas Orgis2018-01-233-2/+58
| | | | | | | | | | * src/patch.c (main): Create git diff files with indicated mode. * tests/file-create-modes: New test case. * tests/Makefile.am (TESTS): Add test case. This fixes building current Linux 4.14.x from the signed tarball and patch file, where the patch creates a script with the executable bit set.
* gnulib: update to latestAndreas Gruenbacher2018-01-231-0/+0
|
* Don't use an undocumented Autoconf macroBruno Haible2018-01-231-3/+3
| | | | * configure.ac: Use AC_CONFIG_HEADERS instead of AC_CONFIG_HEADER.
* Don't allow hunks to overlapAndreas Gruenbacher2017-09-063-3/+59
| | | | | | * src/patch.c (locate_hunk): Don't allow a hunk to overlap with the previous one. * tests/false-match: Add regression test.
* patch.man: Clarify --forward descriptionAndreas Gruenbacher2017-09-061-2/+2
|
* gnulib: update to latestAndreas Gruenbacher2017-09-044-3/+16
|
* Rename canonicalize global variableTim Waugh2017-02-224-6/+6
| | | | | | | | | | | | | | | | | * src/common.h, src/merge.c (context_matches_file), src/patch.c (get_some_switches, patch_match), src/pch.c(another_hunk): Rename the global variable 'canonicalize' to 'canonicalize_ws'. Patch uses a global variable 'canonicalize' as part of its implementation of the --ignore-whitespace flag. In glibc there is a function canonicalize(): https://www.gnu.org/software/libc/manual/html_node/FP-Bit-Twiddling.html#index-canonicalize Rename the global variable so that it will not conflict. Original bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1422463
* Add a missing NULL check in parse_nameHanno Boeck2016-08-101-1/+5
| | | | | * src/util.c (parse_name): parse_c_string() can fail and return NULL. Check for that so that we won't access the NULL pointer here.
* Fix out-of-bounds access to lines in a patchHanno Boeck2016-08-101-1/+1
| | | | | | This bug can trigger with malformed patches. * src/pch.c (pch_write_line): Avoid out-of-bounds access to p_line[line][p_len[line] - 1] when p_len[line] is 0.
* tests: use $PATCH rather than hard-coded pathJim Meyering2016-07-311-1/+1
| | | | * tests/git-cleanup: Don't hard-code program name.
* maint: placate a "make syntax-check" ruleJim Meyering2016-07-311-4/+4
| | | | | | * src/pch.c (set_hunkmax): Don't cast return value of xmalloc. (grow_hunkmax): Likewise for two uses of realloc that the syntax-check rule did not detect.
* maint: avoid new warning-errors from gcc-6.1Jim Meyering2016-07-313-6/+7
| | | | | | | | | | | | | | | | | | | | | When configured with --enable-gcc-warnings and gcc-6.1, ... * src/safe.c (count_path_components): Use _GL_ATTRIBUTE_PURE, to avoid an error from -Werror=suggest-attribute=pure. * src/util.h (filename_is_safe): Likewise. * src/patch.c (main): Placate -Werror=format= by casting pch_mode's mode_t return type to the "unsigned int" required to match the %o format string. * src/patch.c (delete_files): Correct indentation, to avoid this error from -Werror=misleading-indentation: patch.c: In function 'delete_files': patch.c:1816:4: error: this 'if' clause does not guard... if (verbosity == VERBOSE) ^~ patch.c:1820:6: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if' move_file (0, 0, 0, file_to_delete->name, mode, ^~~~~~~~~
* gnulib: update to latestJim Meyering2016-07-312-0/+1
|
* Fix broken git-style patch behaviorAndreas Gruenbacher2016-07-273-17/+77
| | | | | | | | | | | | | | | | | When a git-syle patch is applied, all file modifications are done to temporary files which are put in place when the patch ends. When a patch fails, GNU patch was trying to "roll back" to the start. A bug in that code that lead to accidental file deletion was recently discovered by Richard Weinberger <richard@nod.at>. Even worse though, GNU patch should not exhibit this "rollback" behavior in the first place; that's not what people expect. Instead, the files modified so far should be put in place. * src/patch.c (cleanup): Put output files processed successfully in place instead of trying to "roll back" to the start. (forget_output_files): Remove obsolete (and broken) function. * tests/git-cleanup: New broken git-style patch test case that exercises the cleanup path. * tests/Makefile.am (TESTS): Add new test case.
* Fix inname test caseAndreas Gruenbacher2016-07-274-1/+51
| | | | | | | | | | | | | * src/safe.h (unsafe): New flag to allow turning off safe file operations. * src/safe.c (safe_xstat, safe_open, safe_rename, safe_mkdir, safe_rmdir, safe_unlink, safe_symlink, safe_chmod, safe_lchown, safe_lutimens, safe_readlink, safe_access): When safe file operations are turned off, skip safe path traversal. Any symlink checks of the last path component are still done though. * src/patch.c (main): When the file to patch is specified on the command line, turn off safe file operations. * tests/inname: Fix typo in test.