Commit Graph

5872 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Patrick Steinhardt
fc2ef5143b index: fix memory leak on error case 2016-10-01 17:40:34 +02:00
Christian Schlack
b726c53991 Fix return value of openssl_read (infinite loop)
openssl_read should return -1 in case of error.

SSL_read returns values <= 0 in case of error.

A return value of 0 can lead to an infinite loop, so the return value
of ssl_set_error will be returned if SSL_read is not successful (analog
to openssl_write).
2016-10-01 17:40:33 +02:00
Carlos Martín Nieto
16541b864d tag: ignore extra header fields
While no extra header fields are defined for tags, git accepts them by
ignoring them and continuing the search for the message. There are a few
tags like this in the wild which git parses just fine, so we should do
the same.
2016-10-01 17:40:33 +02:00
Edward Thomson
ccfacb8bb1 leaks: call xdl_free_classifier 2016-04-11 16:17:04 -04:00
Carlos Martín Nieto
2c1bc36d56 Plug a few leaks 2016-04-11 16:15:33 -04:00
Edward Thomson
af753aba14 tree: drop the now-unnecessary entries vector
Remove the now-unnecessary entries vector.  Add `git_array_search`
to binary search through an array to accomplish this.
2016-04-11 15:58:59 -04:00
Carlos Martín Nieto
13ebf7bdbc tree: store the entries in a growable array
Take advantage of the constant size of tree-owned arrays and store them
in an array instead of a pool. This still lets us free them all at once
but lets the system allocator do the work of fitting them in.
2016-04-11 15:58:58 -04:00
Carlos Martín Nieto
26f2cefb81 tree: re-use the id and filename in the odb object
Instead of copying over the data into the individual entries, point to
the originals, which are already in a format we can use.
2016-04-11 15:58:58 -04:00
Carlos Martín Nieto
177890838a ignore: don't use realpath to canonicalize path
If we're looking for a symlink, realpath will give us the resolved path,
which is not what we're after, but a canonicalized version of the path
the user asked for.
2016-04-11 15:58:58 -04:00
Edward Thomson
a13c1ec206 config: don't write section header if we're in it
If we hit the EOF while trying to write a new value, it may be that
we're already in the section that we were looking for.  If so, do not
write a (duplicate) section header, just write the value.
2016-04-11 15:58:58 -04:00
Carlos Martín Nieto
3e2e8240c0 refs: provide a more general error message for dwim
If we cannot dwim the input, set the error message to be explicit about
that. Otherwise we leave the error for the last failed lookup, which
can be rather unexpected as it mentions a remote when the user thought
they were trying to look up a branch.
2016-04-11 15:58:57 -04:00
Patrick Steinhardt
56da07cbcb xdiff/xprepare: fix a memory leak
The xdl_prepare_env() function may initialise an xdlclassifier_t
data structure via xdl_init_classifier(), which allocates memory
to several fields, for example 'rchash', 'rcrecs' and 'ncha'.
If this function later exits due to the failure of xdl_optimize_ctxs(),
then this xdlclassifier_t structure, and the memory allocated to it,
is not cleaned up.

In order to fix the memory leak, insert a call to xdl_free_classifier()
before returning.

This patch was originally written by Ramsay Jones (see commit
87f16258367a3b9a62663b11f898a4a6f3c19d31 in git.git).
2016-04-11 15:58:57 -04:00
Patrick Steinhardt
3ec0f2e37d xdiff/xprepare: use the XDF_DIFF_ALG() macro to access flag bits
Commit 307ab20b3 ("xdiff: PATIENCE/HISTOGRAM are not independent option
bits", 19-02-2012) introduced the XDF_DIFF_ALG() macro to access the
flag bits used to represent the diff algorithm requested. In addition,
code which had used explicit manipulation of the flag bits was changed
to use the macros.

However, one example of direct manipulation remains. Update this code to
use the XDF_DIFF_ALG() macro.

This patch was originally written by Ramsay Jones (see commit
5cd6978a9cfef58de061a9525f3678ade479564d in git.git).
2016-04-11 15:58:57 -04:00
Carlos Martín Nieto
c86a65be4c config: don't special-case multivars that don't exist yet
This special-casing ignores that we might have a locked file, so the
hashtable does not represent the contents of the file we want to
write. This causes multivar writes to overwrite entries instead of add
to them when under lock.

There is no need for this as the normal code-path will write to the file
just fine, so simply get rid of it.
2016-04-11 15:58:57 -04:00
Carlos Martin Nieto
a1cf26448a win32: free thread-local data on thread exit 2016-04-11 15:58:57 -04:00
Carlos Martín Nieto
e97d2d7000 commit: fix extraction of single-line signatures
The function to extract signatures suffers from a similar bug to the
header field finding one by having an unecessary line feed check as a
break condition of its loop.

Fix that and add a test for this single-line signature situation.
2016-04-11 15:58:57 -04:00
Carlos Martín Nieto
d8fcafb2ca Split the page size from the mmap alignment
While often similar, these are not the same on Windows. We want to use the page
size on Windows for the pools, but for mmap we need to use the allocation
granularity as the alignment.

On the other platforms these values remain the same.
2016-04-11 15:58:56 -04:00
Dirkjan Bussink
4e91020c85 Start error string with lower case character 2016-04-11 15:58:56 -04:00
Dirkjan Bussink
c1ec732f46 Setup better defaults for OpenSSL ciphers
This ensures that when using OpenSSL a safe default set of ciphers
is selected. This is done so that the client communicates securely
and we don't accidentally enable unsafe ciphers like RC4, or even
worse some old export ciphers.

Implements the first part of https://github.com/libgit2/libgit2/issues/3682
2016-04-11 15:58:56 -04:00
Patrick Steinhardt
89e7604c3a config_cache: check return value of git_config__lookup_entry
Callers of `git_config__cvar` already handle the case where the
function returns an error due to a failed configuration variable
lookup, but we are actually swallowing errors when calling
`git_config__lookup_entry` inside of the function.

Fix this by returning early when `git_config__lookup_entry`
returns an error. As we call `git_config__lookup_entry` with
`no_errors == false` which leads us to call `get_entry` with
`GET_NO_MISSING` we will not return early when the lookup fails
due to a missing entry. Like this we are still able to set the
default value of the cvar and exit successfully.
2016-04-11 15:58:56 -04:00
Patrick Steinhardt
18c4ae70d1 filebuf: handle write error in lock_file
When writing to a file with locking not check if writing the
locked file actually succeeds. Fix the issue by returning error
code and message when writing fails.
2016-04-11 15:58:56 -04:00
Patrick Steinhardt
f17ed63759 blame: handle error when resoling HEAD in normalize_options
When normalizing options we try to look up HEAD's OID. While this
action may fail in malformed repositories we never check the
return value of the function.

Fix the issue by converting `normalize_options` to actually
return an error and handle the error in `git_blame_file`.
2016-04-11 15:58:56 -04:00
Patrick Steinhardt
dd78d7d15b blame_git: handle error returned by git_commit_parent 2016-04-11 15:58:55 -04:00
Patrick Steinhardt
8d3ee96ada refdb_fs: fail if refcache returns NULL pointer
We usually check entries returned by `git_sortedcache_entry` for
NULL pointers. As we have a write lock in `packed_write`, though,
it really should not happen that the function returns NULL.

Assert that ref is not NULL to silence a Coverity warning.
2016-04-11 15:58:55 -04:00
Patrick Steinhardt
851c51abdf diff_tform: fix potential NULL pointer access
When the user passes in a diff which has no repository associated
we may call `git_config__get_int_force` with a NULL-pointer
configuration. Even though `git_config__get_int_force` is
designed to swallow errors, it is not intended to be called with
a NULL pointer configuration.

Fix the issue by only calling `git_config__get_int_force` only
when configuration could be retrieved from the repository.
2016-04-11 15:58:55 -04:00