Commit Graph

9211 Commits

Author SHA1 Message Date
Edward Thomson
6a35e74cb3 leaks: fix some leaks in the tests 2016-04-11 16:16:55 -04:00
Carlos Martín Nieto
2c1bc36d56 Plug a few leaks 2016-04-11 16:15:33 -04:00
Edward Thomson
5cc7a5c7b3 tests: skip the unreadable file tests as root
When running as root, skip the unreadable file tests, because, well,
they're probably _not_ unreadable to root unless you've got some
crazy NSA clearance-level honoring operating system shit going on.
2016-04-11 16:05:51 -04:00
Edward Thomson
1d59c85aad status: update test to include valid OID 2016-04-11 15:59:12 -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
21d8832e74 config::write::repeated: init our buffer 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
e8d5df9edc config: show we write a spurious duplicated section header
We should notice that we are in the correct section to add. This is a
cosmetic bug, since replacing any of these settings does work.
2016-04-11 15:58:58 -04:00
Edward Thomson
b6130fe15e refs::create: strict object creation on by default
When we turned strict object creation validation on by default, we
forgot to inform the refs::create tests of this.  They, in fact,
believed that strict object creation was off by default.  As a result,
their cleanup function went and turned strict object creation off for
the remaining tests.
2016-04-11 15:58:58 -04:00
Carlos Martín Nieto
ba52879b46 reset: use real ids for the tests
This lets us run with strict object creation on.
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
Andreas Henriksson
ab062a3938 tests: fix core/stream test when built with openssl off
When passing -DUSE_OPENSSL:BOOL=OFF to cmake the testsuite will
fail with the following error:

core::stream::register_tls [/tmp/libgit2/tests/core/stream.c:40]
  Function call failed: (error)
  error -1 - <no message>

Fix test to assume failure for tls when built without openssl.
While at it also fix GIT_WIN32 cpp to check if it's defined
or not.
2016-04-11 15:58:57 -04:00
Carlos Martín Nieto
fe1f47776f Add a no-op size_t typedef for the doc parser
Clang's documentation parser, which we use in our documentation system
does not report any comments for functions which use size_t as a type.

The root cause is buried somewhere in libclang but we can work around it
by defining the type ourselves. This typedef makes sure that libclang
sees it and that we do not change its size.
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
Marc Strapetz
9a668abd34 Option "LIBGIT2_PREFIX" to set the CMAKE's TARGET_PROPERTIES PREFIX
This is especially useful in combination with MinGW to yield the
Windows-compliant DLL name "git2.dll" instead of "libgit2.dll"
2016-04-11 15:58:56 -04:00
Marc Strapetz
f587f38c08 CMake: do not overwrite but only append to CMAKE_C_FLAGS_DEBUG
This is useful to force "smart" IDEs (like CLIon) to use debug
flag -g even it may have decided that "-D_DEBUG" (which is
already present) is sufficient.
2016-04-11 15:58:56 -04:00
Dirkjan Bussink
cdde081b35 Use general cl_git_fail because the error is generic 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
0b357e2eed coverity: report errors when uploading tarball
Curl by default does not report errors by setting the error code.
As the upload can fail through several conditions (e.g. the rate
limit, leading to unauthorized access) we should indicate this
information in Travis CI.

To improve upon the behavior, use `--write-out=%{http_code}` to
write out the HTTP code in addition to the received body and
return an error if the code does not equal 201.
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
Patrick Steinhardt
d96c063852 submodule: avoid passing NULL pointers to strncmp
In C89 it is undefined behavior to pass `NULL` pointers to
`strncmp` and later on in C99 it has been explicitly stated that
functions with an argument declared as `size_t nmemb` specifying
the array length shall always have valid parameters, no matter if
`nmemb` is 0 or not (see ISO 9899 §7.21.1.2).

The function `str_equal_no_trailing_slash` always passes its
parameters to `strncmp` if their lengths match. This means if one
parameter is `NULL` and the other one either `NULL` or a string
with length 0 we will pass the pointers to `strncmp` and cause
undefined behavior.

Fix this by explicitly handling the case when both lengths are 0.
2016-04-11 15:58:55 -04:00
Patrick Steinhardt
1a16e8b057 pack-objects: fix memory leak on overflow 2016-04-11 15:58:55 -04:00
Patrick Steinhardt
e114bbac89 index: assert required OID are non-NULL 2016-04-11 15:58:55 -04:00
Patrick Steinhardt
d0780b8133 object: avoid call of memset with ouf of bounds pointer
When computing a short OID we do this by first copying the
leading parts into the new OID structure and then setting the
trailing part to zero. In the case of the desired length being
`GIT_OID_HEXSZ - 1` we will call `memset` with an out of bounds
pointer and a length of 0. While this seems to cause no problems
for common platforms the C89 standard does not explicitly state
that calling `memset` with an out of bounds pointer and
length of 0 is valid.

Fix the potential issue by using the newly introduced
`git_oid__cpy_prefix` function.
2016-04-11 15:58:55 -04:00
Edward Thomson
fa4b93a61c backport git_oid__cpy_prefix 2016-04-11 15:58:54 -04:00
Patrick Steinhardt
faf823dcca tests: transport: fix memory leaks with registering transports 2016-04-11 14:15:28 -04:00
Piet Brauer
0370dae1ad Check for __CLANG_INTTYPES_H
This fixes an issue in Xcode 7.3 in objective-git where we get the error
"Include of non-modular header file in module". Not importing this
header again fixes the issue.
2016-04-11 14:14:32 -04:00
Patrick Steinhardt
e39ad747f7 config_file: handle missing quotation marks in section header
When parsing a section header we expect something along the
format of '[section "subsection"]'. When a section is
mal-formated and is entirely missing its quotation marks we catch
this case by observing that `strchr(line, '"') - strrchr(line,
'"') = NULL - NULL = 0` and error out. Unfortunately, the error
message is misleading though, as we state that we are missing the
closing quotation mark while we in fact miss both quotation
marks.

Improve the error message by explicitly checking if the first
quotation mark could be found and, if not, stating that quotation
marks are completely missing.
2016-04-11 14:14:25 -04:00
Patrick Steinhardt
ffb1f41949 describe: handle error code returned by git_pqueue_insert 2016-04-11 14:14:15 -04:00
Carlos Martín Nieto
4ebf745f06 mwindow: free unused windows if we fail to mmap
The first time may be due to memory fragmentation or just bad luck on a
32-bit system. When we hit the mmap error for the first time, free up
the unused windows and try again.
2016-04-11 14:13:34 -04:00
Chris Hescock
9ee498e800 Only buffer if necessary. 2016-04-11 14:13:11 -04:00
Edward Thomson
eb09ead246 odb: improved not found error messages
When looking up an abbreviated oid, show the actual (abbreviated) oid
the caller passed instead of a full (but ambiguously truncated) oid.
2016-04-11 14:12:40 -04:00
P.S.V.R
cdded6309a Remove duplicated calls to git_mwindow_close 2016-04-11 14:11:55 -04:00
Chris Hescock
e3862c9fb2 Buffer sideband packet data
The inner packet may be split across multiple sideband packets.
2016-04-11 14:11:51 -04:00
Yong Li
8ec3d88f58 Avoid subtraction overflow in git_indexer_commit 2016-04-11 14:11:41 -04:00
Chris Bargren
4a93a7fcc4 Tabs 2016-04-11 14:11:33 -04:00