Compare commits

...

4 Commits
v2.8 ... master

Author SHA1 Message Date
Daniel Black
d161c9a9db Skip read-only check when output file specified
Only check if input files are read-only when overwriting them; skip
that check when the output goes to a different file.

* src/patch.c (main): Set read_only_behavior to RO_IGNORE when an output
file has been specified.
* tests/read-only-files: Add test case.
2025-05-01 13:40:20 +02:00
Andreas Gruenbacher
4c302306a8 Reject empty filenames
* src/safe.c (safe_xstat): Reject empty pathnames.
* tests/bad-filenames: Add a new test.
* src/patch.c (main): Don't check if the input file is writable when
we're not going to modify it.
2025-04-05 17:26:56 +02:00
Andreas Gruenbacher
aea66268c9 Add some missing filename quoting
* src/patch.c (main): Quote outname.
2025-04-05 17:25:45 +02:00
Andreas Gruenbacher
77c27209f6 Fix 'make release' for proper releases
(Proper releases have a signed git tag.)
2025-03-29 22:40:26 +01:00
6 changed files with 26 additions and 3 deletions

2
NEWS
View File

@ -1,3 +1,5 @@
Unreleased changes:
Changes in version 2.8:
* The --follow-symlinks option now applies to output files as well as input.

2
cfg.mk
View File

@ -18,6 +18,8 @@ config_h_header = <(common|config)\.h>
ifeq ($(RELEASE_TYPE),alpha)
news-check-regexp = "Unreleased changes"
else
news-check-regexp = '^Changes in version $(VERSION_REGEXP):'
endif
release-prep-hook =

View File

@ -204,7 +204,10 @@ main (int argc, char **argv)
init_output (&outstate);
if (outfile)
outstate.ofp = open_outfile (outfile);
{
outstate.ofp = open_outfile (outfile);
read_only_behavior = RO_IGNORE;
}
/* Make sure we clean up in case of disaster. */
init_signals ();
@ -323,7 +326,8 @@ main (int argc, char **argv)
}
}
if (read_only_behavior != RO_IGNORE
if (! skip_rest_of_patch
&& read_only_behavior != RO_IGNORE
&& ! inerrno && ! S_ISLNK (instat.st_mode)
&& safe_access (inname, W_OK) != 0)
{
@ -616,7 +620,7 @@ main (int argc, char **argv)
struct stat outstat;
if (stat_file (outname, &outstat) != 0)
say ("Cannot stat file %s, skipping backup\n", outname);
say ("Cannot stat file %s, skipping backup\n", quotearg (outname));
else
output_file (&(struct outfile) { .name = outname },
&outstat, nullptr, nullptr,

View File

@ -571,6 +571,8 @@ safe_xstat (char *pathname, struct stat *buf, int flags)
int dirfd = traverse_path (&pathname, false);
if (dirfd == DIRFD_INVALID)
return -1;
if (! strcmp (pathname, ""))
return EINVAL;
return fstatat (dirfd, pathname, buf, flags);
}

View File

@ -200,3 +200,11 @@ No file to patch. Skipping patch.
1 out of 1 hunk ignored
status: 1
EOF
# Empty filenames are not allowed:
check 'emit_patch f | patch -r- "" || echo status: $?' <<EOF
File '' is not a regular file -- refusing to patch
1 out of 1 hunk ignored
status: 1
EOF

View File

@ -67,3 +67,8 @@ check 'patch -f -p0 --read-only=ignore < f.diff || echo "Status: $?"' <<EOF
patching file f
patching file f
EOF
check 'patch -o - f /dev/null || echo "Status: $?"' <<EOF
patching file - (read from f)
three
EOF