Commit Graph

9 Commits

Author SHA1 Message Date
Ondřej Pohořelský
4da6d5f30c Update license year 2021-06-01 14:53:58 +02:00
brian m. carlson
a66274014c
tools: add a function to properly canonicalize paths
Git consistently uses canonicalized paths internally.  This is for many
reasons, but mostly to verify that a single path is within a repository.
In order to interoperate properly with Git, we need to canonicalize
paths and do it in the same way as Git.

On Unix systems, to canonicalize a path, it is sufficient to make the
path absolute and then resolve any symlinks.  Go provides two functions
to do these two steps, filepath.Abs and filepath.EvalSymlinks, and they
work as advertised.

Windows, however, has much more complex path handling and these
functions do not handle all cases.  The typical way to canonicalize
paths on Windows is using GetFinalPathNameByHandle, and this is the
technique Git uses.

Go, however, does not provide a general API to canonicalize paths,
unlike Rust's std::fs::canonicalize and similar functionality in myriad
other languages.  Therefore, in order to get this working on Windows,
let's add a function to canonicalize paths in the appropriate system
way, one for Unix systems and one for Windows.  The code comes from Go's
standard library, so update the copyright and license accordingly.

Update the CanonicalizePath function to use the new function.  We
duplicate the Abs call because we an absolute path in CanonicalizePath
in some cases even if the path is missing, whereas the new function
needs to do it in all cases because we will use it other situations in
the future.  This should be a simple string check, so it should not
involve an extra system call or other overhead.
2021-03-01 22:10:19 +00:00
brian m. carlson
74d5f2397f
subprocess: avoid using relative program names
When Go runs a program with os.exec, it uses the LookPath function to
look up the path name if the path does not contain a path separator.  On
Unix, this provides the standard Unix semantics by looking in PATH.
However, on Windows, it also looks in the current directory as well to
emulate the behavior of CMD.

Unfortunately, this is a well-known security flaw on Windows and similar
behavior there is the source for several whole classes of security
vulnerabilities.  This leads to an untrusted repository being able to
create a git.bat file that gets executed in preference to our trusted
path for the git binary.

Since we don't want to rely on Go fixing this behavior, let's import
some code from Go to provide the Unix semantics for LookPath, which are
secure if the user hasn't put the current directory in PATH.  That
should provide secure behavior in this case.  Fortunately, our code goes
through one particular place to run all commands, so this is a
relatively simple fix.

Update the various copyright and license files to reflect our imported
code.
2020-11-02 20:57:56 +00:00
dan2468
dfeb697c35
updated copyright year 2020-01-22 19:26:10 +02:00
brian m. carlson
2a6da03fcf
LICENSE: document use of other Go modules
Document that we use other Go modules which are available under
different license terms, so that folks aren't confused, and point them
to the other license files.
2020-01-15 18:23:50 +00:00
Jess
1b7b445934
Update LICENSE.md
update license year
2018-07-30 21:17:02 +08:00
Ben Balter
6faa2589cf Add copyright date to license 2016-11-23 12:23:13 -05:00
Ben Balter
4ccebb5daa Remove the license description from the license itself 2016-11-23 11:40:24 -05:00
Julio Avalos
285389d73c Rename LICENSE to LICENSE.md 2015-08-04 14:57:11 -07:00