10 Commits
Author SHA1 Message Date
Shannon Booth e0ae942bae system: do not treat a drive-relative path as absolute
"C:\foo" names the root of drive C, but "C:foo" names foo relative to
whatever the current directory on C happens to be. Classifying the
second as absolute means it is resolved from a root it does not name.

Rejecting absolute names was also the only thing keeping a
drive-relative name out of a patch, so is_safe_patch_path() now refuses
a colon itself. A colon never appears in a Windows file name, since
"file:stream" names an alternate data stream of "file" rather than a
file of that name.
2026-08-01 18:50:32 +02:00
Shannon Booth 5f4812b199 parser: reject octal escapes larger than a byte
Quoted paths encode each filename byte with at most three octal digits.
Accumulate in a wider type and reject values above 0377 instead of
relying on an implicit narrowing conversion and wraparound.
2026-08-01 15:33:12 +02:00
Shannon Booth 0f21e675b5 patch: refuse patch names which could escape the directory being patched
A name taken from a patch was used as is, so an absolute name or one
which kept a '..' component after -p stripping could read and write
anywhere on the filesystem.

This seems to have been settled on as 'unsafe', so refuse such paths
after stripping, so that stripping may still turn an unsafe name into a
safe one.
2026-07-25 20:00:41 +02:00
Shannon Booth d70b768359 parser: factor some functions to make use of line parser
In particular, this has the nice side effect of slightly simplifying
parse_git_header_name to not have a dead check for the git header.

We are also able to remove LineParser::end() and LineParser::current()
with these changes.

Finally, this allows us to get rid of the substr with magic number
checks when parsing file names.
2023-05-14 14:15:07 +12:00
Shannon Booth a922cd71b7 parser: fix strip including backslash on non windows platforms
Which broke things if there was a backslash in the filename as it was
being considered a path separator.
2023-03-19 16:05:56 +13:00
Shannon Booth af40b24b12 tests: put test library headers under a patch folder
For much better symmetry with product code.
2022-12-27 14:26:45 -08:00
Shannon Booth e154a7e0aa tests: switch from google test entirely to patch test
We now have good enough support to make this move and _finally_ get rid
of the google test dependency!
2022-12-27 14:26:45 -08:00
Shannon Booth bcbda153c0 parser: add support for parsing quoted octal escape codes
I discovered this when trying to test implementing support for non-ASCII
filenames for patch file paths when comparing these files using the diff
tool. Apparently these may not be UTF8 encoded, and may instead be
expressed in octal.
2022-09-02 22:30:41 -07:00
Shannon Booth 5fe3373e2c parser: support unquoted filenames with spaces in them
Which appears to be what git uses, as opposed to what I have mainly been
testing against using GNU diff.

This took a while to figure out as originally I did not realise that the
git style patches were placing a trailing tab after the filename in for
these patches. The tab seems to be the only way which we can possibly
distinguish these filenames from a timestamp since we also support using
spaces as a timestamp to filename separator.
2022-07-03 19:49:52 +12:00
Shannon Booth 5230d9ed60 patch: initial commit 2022-07-03 19:49:48 +12:00