Commit Graph

10689 Commits

Author SHA1 Message Date
Carlos Martín Nieto
b64722fd52 SecureTransport: handle NULL trust on success
The `SSLCopyPeerTrust` call can succeed but fail to return a trust
object if it can't load the certificate chain and thus cannot check the
validity of a certificate. This can lead to us calling `CFRelease` on a
`NULL` trust object, causing a crash.

Handle this by returning ECERTIFICATE.
2016-10-01 17:40:41 +02:00
Edward Thomson
1fafead53a sysdir: use the standard init pattern
Don't try to determine when sysdirs are uninitialized.  Instead, simply
initialize them all at `git_libgit2_init` time and never try to
reinitialize, except when consumers explicitly call `git_sysdir_set`.

Looking at the buffer length is especially problematic, since there may
no appropriate path for that value.  (For example, the Windows-specific
programdata directory has no value on non-Windows machines.)

Previously we would continually trying to re-lookup these values,
which could get racy if two different threads are each calling
`git_sysdir_get` and trying to lookup / clear the value simultaneously.
2016-10-01 17:40:41 +02:00
Patrick Steinhardt
85addddf4c refspec: do not set empty rhs for fetch refspecs
According to git-fetch(1), "[t]he colon can be omitted when <dst>
is empty." So according to git, the refspec "refs/heads/master"
is the same as the refspec "refs/heads/master:" when fetching
changes. When trying to fetch from a remote with a trailing
colon with libgit2, though, the fetch actually fails while it
works when the trailing colon is left out. So obviously, libgit2
does _not_ treat these two refspec formats the same for fetches.

The problem results from parsing refspecs, where the resulting
refspec has its destination set to an empty string in the case of
a trailing colon and to a `NULL` pointer in the case of no
trailing colon. When passing this to our DWIM machinery, the
empty string gets translated to "refs/heads/", which is simply
wrong.

Fix the problem by having the parsing machinery treat both cases
the same for fetch refspecs.
2016-10-01 17:40:41 +02:00
Edward Thomson
d711165d03 repository: don't cast to int for no reason
And give it a default so that some compilers don't (unnecessarily)
complain.
2016-10-01 17:40:41 +02:00
David Turner
9894c7ddeb remote: Handle missing config values when deleting a remote
Somehow I ended up with the following in my ~/.gitconfig:
[branch "master"]
remote = origin
merge = master
rebase = true

I assume something went crazy while I was running the git.git tests
some time ago, and that I never noticed until now.

This is not a good configuration, but it shouldn't cause problems. But
it does. Specifically, if you have this in your config, and you
perform the following set of actions:

create a remote
fetch from that remote
create a branch off of the remote master branch called "master"
delete the branch
delete the remote

The remote delete fails with the message "Could not find key
'branch.master.rebase' to delete". This is because it's iterating over
the config entries (including the ones in the global config) and
believes that there is a master branch which must therefore have these
config keys.

https://github.com/libgit2/libgit2/issues/3856
2016-10-01 17:40:41 +02:00
Patrick Steinhardt
49188d2b29 blame: do not decrement commit refcount in make_origin
When we create a blame origin, we try to look up the blob that is
to be blamed at a certain revision. When this lookup fails, e.g.
because the file did not exist at that certain revision, we fail
to create the blame origin and return `NULL`. The blame origin
that we have just allocated is thereby free'd with
`origin_decref`.

The `origin_decref` function does not only decrement reference
counts for the blame origin, though, but also for its commit and
blob. When this is done in the error case, we will cause an
uneven reference count for these objects. This may result in
hard-to-debug failures at seemingly unrelated code paths, where
we try to access these objects when they in fact have already
been free'd.

Fix the issue by refactoring `make_origin` such that we only
allocate the object after the only function that may fail so that
we do not have to call `origin_decref` at all. Also fix the
`pass_blame` function, which indirectly calls `make_origin`, to
free the commit when `make_origin` failed.
2016-10-01 17:40:41 +02:00
Krishna Ram Prakash R
1edbfa1ffe Fixed bug while parsing INT64_MIN 2016-10-01 17:40:40 +02:00
Josh Triplett
a200dc9e1d Fix repository discovery with ceiling_dirs at current directory
git only checks ceiling directories when its search ascends to a parent
directory.  A ceiling directory matching the starting directory will not
prevent git from finding a repository in the starting directory or a
parent directory.  libgit2 handled the former case correctly, but
differed from git in the latter case: given a ceiling directory matching
the starting directory, but no repository at the starting directory,
libgit2 would stop the search at that point rather than finding a
repository in a parent directory.

Test case using git command-line tools:

/tmp$ git init x
Initialized empty Git repository in /tmp/x/.git/
/tmp$ cd x/
/tmp/x$ mkdir subdir
/tmp/x$ cd subdir/
/tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x git rev-parse --git-dir
fatal: Not a git repository (or any of the parent directories): .git
/tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x/subdir git rev-parse --git-dir
/tmp/x/.git

Fix the testsuite to test this case (in one case fixing a test that
depended on the current behavior), and then fix find_repo to handle this
case correctly.

In the process, simplify and document the logic in find_repo():
- Separate the concepts of "currently checking a .git directory" and
  "number of iterations left before going further counts as a search"
  into two separate variables, in_dot_git and min_iterations.
- Move the logic to handle in_dot_git and append /.git to the top of the
  loop.
- Only search ceiling_dirs and find ceiling_offset after running out of
  min_iterations; since ceiling_offset only tracks the longest matching
  ceiling directory, if ceiling_dirs contained both the current
  directory and a parent directory, this change makes find_repo stop the
  search at the parent directory.
2016-10-01 17:40:40 +02:00
Patrick Steinhardt
c7a033690e cmake: do not use -fPIC for MSYS2
The MSYS2 build system automatically compiles all code with position-independent
code. When we manually add the -fPIC flag to the compiler flags, MSYS2 will
loudly complain about PIC being the default and thus not required.

Fix the annoyance by stripping -fPIC in MSYS2 enviroments like it is already
done for MinGW.
2016-10-01 17:40:40 +02:00
Edward Thomson
cc43d185e3 README: update "Getting Help" section 2016-10-01 17:40:40 +02:00
Edward Thomson
ce124fc793 README: improve contributing paragraph 2016-10-01 17:40:40 +02:00
Edward Thomson
90ec160586 README: disambiguate what to distribute source of
Indicate that if you make changes to libgit2 that you must distribute
the source _to libgit2_, not the source _of your program_.
2016-10-01 17:40:40 +02:00
Patrick Steinhardt
bb582f073c threads: add platform-independent thread initialization function 2016-10-01 17:40:40 +02:00
Patrick Steinhardt
5d03db8146 win32: rename pthread.{c,h} to thread.{c,h}
The old pthread-file did re-implement the pthreads API with exact symbol
matching. As the thread-abstraction has now been split up between Unix- and
Windows-specific files within the `git_` namespace to avoid symbol-clashes
between libgit2 and pthreads, the rewritten wrappers have nothing to do with
pthreads anymore.

Rename the Windows-specific pthread-files to honor this change.
2016-10-01 17:40:39 +02:00
Patrick Steinhardt
961bdbdfac threads: remove now-useless typedefs 2016-10-01 17:40:39 +02:00
Patrick Steinhardt
2aa5c6ff8a threads: remove unused function pthread_num_processors_np
The function pthread_num_processors_np is currently unused and superseded by the
function `git_online_cpus`. Remove the function.
2016-10-01 17:40:39 +02:00
Patrick Steinhardt
68343f26dd threads: split up OS-dependent rwlock code 2016-10-01 17:40:39 +02:00
Patrick Steinhardt
fabd477125 threads: split up OS-dependent thread-condition code 2016-10-01 17:40:39 +02:00
Patrick Steinhardt
1b8253168a threads: remove unused function pthread_cond_broadcast 2016-10-01 17:40:39 +02:00
Patrick Steinhardt
40b243bf5a threads: split up OS-dependent mutex code 2016-10-01 17:40:38 +02:00
Patrick Steinhardt
fc2b97dd4e threads: split up OS-dependent thread code 2016-10-01 17:40:38 +02:00
Sim Domingo
286e7dbd4b fix error message SHA truncation in git_odb__error_notfound() 2016-10-01 17:40:38 +02:00
David Brooks
4c06f3e7dc HTTP authentication scheme name is case insensitive. 2016-10-01 17:40:38 +02:00
Edward Thomson
ac44d354c8 checkout: use empty baseline when no index
When no index file exists and a baseline is not explicitly provided, use
an empty baseline instead of trying to load `HEAD`.
2016-10-01 17:40:38 +02:00
Edward Thomson
a574d84352 documentation: improve docs for checkout_head
`git_checkout_head` is sadly misunderstood as something that can
switch branches.  It cannot.  Update the documentation to reflect this.
2016-10-01 17:40:38 +02:00
Jason Haslam
27008e849f fetch: Fixed spurious update callback for existing tags. 2016-10-01 17:40:37 +02:00
Patrick Steinhardt
d1fb89dd2f global: clean up crt only after freeing tls data
The thread local storage is used to hold some global state that
is dynamically allocated and should be freed upon exit. On
Windows, we clean up the C run-time right after execution of
registered shutdown callbacks and before cleaning up the TLS.

When we clean up the CRT, we also cause it to analyze for memory
leaks. As we did not free the TLS yet this will lead to false
positives.

Fix the issue by first freeing the TLS and cleaning up the CRT
only afterwards.
2016-10-01 17:40:37 +02:00
Patrick Steinhardt
6e0d473bee tests: fix memory leaks in checkout::typechange 2016-10-01 17:40:37 +02:00
Patrick Steinhardt
246d25b3ce index: fix NULL pointer access in index_remove_entry
When removing an entry from the index by its position, we first
retrieve the position from the index's entries and then try to
remove the retrieved value from the index map with
`DELETE_IN_MAP`. When `index_remove_entry` returns `NULL` we try
to feed it into the `DELETE_IN_MAP` macro, which will
unconditionally call `idxentry_hash` and then happily dereference
the `NULL` entry pointer.

Fix the issue by not passing a `NULL` entry into `DELETE_IN_MAP`.
2016-10-01 17:40:37 +02:00
Patrick Steinhardt
1a70960436 transports: smart: fix potential invalid memory dereferences
When we receive a packet of exactly four bytes encoding its
length as those four bytes it can be treated as an empty line.
While it is not really specified how those empty lines should be
treated, we currently ignore them and do not return an error when
trying to parse it but simply advance the data pointer.

Callers invoking `git_pkt_parse_line` are currently not prepared
to handle this case as they do not explicitly check this case.
While they could always reset the passed out-pointer to `NULL`
before calling `git_pkt_parse_line` and determine if the pointer
has been set afterwards, it makes more sense to update
`git_pkt_parse_line` to set the out-pointer to `NULL` itself when
it encounters such an empty packet. Like this it is guaranteed
that there will be no invalid memory references to free'd
pointers.

As such, the issue has been fixed such that `git_pkt_parse_line`
always sets the packet out pointer to `NULL` when an empty packet
has been received and callers check for this condition, skipping
such packets.
2016-10-01 17:40:37 +02:00
Edward Thomson
11408f0e43 index_read_index: invalidate new paths in tree cache
When adding a new entry to an existing index via `git_index_read_index`,
be sure to remove the tree cache entry for that new path.  This will
mark all parent trees as dirty.
2016-10-01 17:40:37 +02:00
Edward Thomson
8be49681a6 test: ensure we can round-trip a written tree
Read a tree into an index, write the index, then re-open the index and
ensure that we are treesame to the original.
2016-10-01 17:40:37 +02:00
Edward Thomson
80745b1256 index_read_index: set flags for path_len correctly
Update the flags to reset the path_len (to emulate `index_insert`)
2016-10-01 17:40:36 +02:00
Edward Thomson
e755f79fd7 index_read_index: differentiate on mode
Treat index entries with different modes as different, which they
are, at least for the purposes of up-to-date calculations.
2016-10-01 17:40:36 +02:00
Edward Thomson
e6a0a85091 index_read_index: reset error correctly
Clear any error state upon each iteration.  If one of the iterations
ends (with an error of `GIT_ITEROVER`) we need to reset that error to 0,
lest we stop the whole process prematurely.
2016-10-01 17:40:36 +02:00
Edward Thomson
6c133a7575 round-trip trees through index_read_index
Read a tree into an index using `git_index_read_index` (by reading
a tree into a new index, then reading that index into the current
index), then write the index back out, ensuring that our new index
is treesame to the tree that we read.
2016-10-01 17:40:36 +02:00
Edward Thomson
feea2849f9 win32: clean up unused warnings in DllMain 2016-10-01 17:40:36 +02:00
Edward Thomson
efadf28d84 filebuf: fix uninitialized warning 2016-10-01 17:40:36 +02:00
Edward Thomson
bcef008f77 cleanup: unused warning 2016-10-01 17:40:35 +02:00
Elan Ruusamäe
68227c431a Update CMakeLists.txt
typo fix
2016-10-01 17:40:35 +02:00
Jason Haslam
85ef6ec5f0 Ignore submodules when checking for merge conflicts in the workdir. 2016-10-01 17:40:35 +02:00
Jason Haslam
70681ff740 checkout: handle dirty submodules correctly
Don't generate conflicts when checking out a modified submodule and the
submodule is dirty or modified in the workdir.
2016-10-01 17:40:35 +02:00
François Revol
26917fd9d1 test: Fix stat() test to mask out unwanted bits
Haiku and Hurd both pass extra bits in struct stat::st_mode.
2016-10-01 17:40:35 +02:00
François Revol
488937c22d CMakeLists: Add libnetwork for Haiku 2016-10-01 17:40:35 +02:00
Carl Edquist
78b5702ed5 Fix comment for GIT_FILEMODE_LINK
0120000 is symbolic link, not commit
2016-10-01 17:40:34 +02:00
Lucas Derraugh
849a1a4345 Fix unused variable 'message' warning 2016-10-01 17:40:34 +02:00
Patrick Steinhardt
cf0396a563 delta-apply: fix sign extension
We compute offsets by executing `off |= (*delta++ << 24)` for
multiple constants, where `off` is of type `size_t` and `delta`
is of type `unsigned char`. The usual arithmetic conversions (see
ISO C89 §3.2.1.5 "Usual arithmetic conversions") kick in here,
causing us to promote both operands to `int` and then extending
the result to an `unsigned long` when OR'ing it with `off`.
The integer promotion to `int` may result in wrong size
calculations for big values.

Fix the issue by making the constants `unsigned long`, causing both
operands to be promoted to `unsigned long`.
2016-10-01 17:40:34 +02:00
Patrick Steinhardt
1fb8a951b6 odb_loose: fix undefined behavior when computing size
An object's size is computed by reading the object header's size
field until the most significant bit is not set anymore. To get
the total size, we increase the shift on each iteration and add
the shifted value to the total size.

We read the current value into a variable of type `unsigned
char`, from which we then take all bits except the most
significant bit and shift the result. We will end up with a
maximum shift of 60, but this exceeds the width of the value's
type, resulting in undefined behavior.

Fix the issue by instead reading the values into a variable of
type `unsigned long`, which matches the required width. This is
equivalent to git.git, which uses an `unsigned long` as well.
2016-10-01 17:40:34 +02:00
Patrick Steinhardt
f627e19662 checkout: set ignorecase=0 when config lookup fails
When `git_repository__cvar` fails we may end up with a
`ignorecase` value of `-1`. As we subsequently check if
`ignorecase` is non-zero, we may end up reporting that data
should be removed when in fact it should not.

Err on the safer side and set `ignorecase = 0` when
`git_repository__cvar` fails.
2016-10-01 17:40:34 +02:00
Carlos Martín Nieto
66633e836f odb: avoid inflating the full delta to read the header
When we read the header, we want to know the size and type of the
object. We're currently inflating the full delta in order to read the
first few bytes. This can mean hundreds of kB needlessly inflated for
large objects.

Instead use a packfile stream to read just enough so we can read the two
varints in the header and avoid inflating most of the delta.
2016-10-01 17:40:34 +02:00