summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* tree: look for conflicts in the new tree when updatingcmn/tree-updater-orderingCarlos Martín Nieto2016-11-141-0/+3
| | | | | | | | | | We look at whether we're trying to replace a blob with a tree during the update phase, but we fail to look at whether we've just inserted a blob where we're now trying to insert a tree. Update the check to look at both places. The test for this was previously succeeding due to the bu where we did not look at the sorted output.
* tree: use the sorted update list in our loopCarlos Martín Nieto2016-11-141-2/+2
| | | | | The loop is made with the assumption that the inputs are sorted and not using it leads to bad outputs.
* Merge pull request #4002 from pks-t/pks/giterr-formatCarlos Martín Nieto2016-11-1410-43/+44
|\ | | | | giterr format
| * path: pass string instead of git_buf to giterr_setPatrick Steinhardt2016-11-141-1/+1
| |
| * checkout: pass string instead of git_buf to `giterr_set`Patrick Steinhardt2016-11-141-2/+2
| |
| * common: cast precision specifiers to intPatrick Steinhardt2016-11-142-3/+3
| |
| * common: use PRIuZ for size_t in `giterr_set` callsPatrick Steinhardt2016-11-145-36/+36
| |
| * common: mark printf-style formatting for `giterr_set`Patrick Steinhardt2016-11-141-1/+2
| |
* | Merge pull request #3983 from pks-t/pks/smart-early-eofCarlos Martín Nieto2016-11-141-2/+6
|\ \ | | | | | | transports: smart: abort on early end of stream
| * | transports: smart: abort receiving packets on end of streamPatrick Steinhardt2016-11-021-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to receive packets from the remote, we loop until either an error distinct to `GIT_EBUFS` occurs or until we successfully parsed the packet. This does not honor the case where we are looping over an already closed socket which has no more data, leaving us in an infinite loop if we got a bogus packet size or if the remote hang up. Fix the issue by returning `GIT_EEOF` when we cannot read data from the socket anymore.
| * | transports: smart: abort ref announcement on early end of streamPatrick Steinhardt2016-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When reading a server's reference announcements via the smart protocol, we expect the server to send multiple flushes before the protocol is finished. If we fail to receive new data from the socket, we will only return an end of stream error if we have not seen any flush yet. This logic is flawed in that we may run into an infinite loop when receiving a server's reference announcement with a bogus flush packet. E.g. assume the last flushing package is changed to not be '0000' but instead any other value. In this case, we will still await one more flush package and ignore the fact that we are not receiving any data from the socket, causing an infinite loop. Fix the issue by always returning `GIT_EEOF` if the socket indicates an end of stream.
* | | Merge pull request #3992 from joshtriplett/env-namespacePatrick Steinhardt2016-11-141-5/+8
|\ \ \ | |_|/ |/| | git_repository_open_ext: fix handling of $GIT_NAMESPACE
| * | git_repository_open_ext: fix handling of $GIT_NAMESPACEJosh Triplett2016-11-111-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The existing code would set a namespace of "" (empty string) with GIT_NAMESPACE unset. In a repository where refs/heads/namespaces/ exists, that can produce incorrect results. Detect that case and avoid setting the namespace at all. Since that makes the last assignment to error conditional, and the previous assignment can potentially get GIT_ENOTFOUND, set error to 0 explicitly to prevent the call from incorrectly failing with GIT_ENOTFOUND.
* | | fileops: fix typos in `git_futils_creat_locked{,with_path}`Patrick Steinhardt2016-11-141-2/+2
| | |
* | | curl_stream: check for -1 after CURLINFO_LASTSOCKETAlex Crichton2016-11-111-0/+6
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We're recently trying to upgrade to the current master of libgit2 in Cargo but we're unfortunately hitting a segfault in one of our tests. This particular test is just a small smoke test that https works (e.g. it's configured in libgit2). It attempts to clone from a URL which simply immediately drops connections after they're accepted (e.g. terminate abnormally). We expect to see a standard error from libgit2 but unfortunately we're seeing a segfault. This segfault is happening inside of the `wait_for` function of `curl_stream.c` at the line `FD_SET(fd, &errfd)` because `fd` is -1. This ends up doing an out-of-bounds array access that faults the program. I tracked back to where this -1 came from to the line here (returned by `CURLINFO_LASTSOCKET`) and added a check to return an error.
* | Merge pull request #3974 from libgit2/pks/synchronize-shutdownPatrick Steinhardt2016-11-041-4/+19
|\ \ | | | | | | global: synchronize initialization and shutdown with pthreads
| * | global: reset global state on shutdown without threadingPatrick Steinhardt2016-11-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When threading is not enabled for libgit2, we keep global state in a simple static variable. When libgit2 is shut down, we clean up the global state by freeing the global state's dynamically allocated memory. When libgit2 is built with threading, we additionally free the thread-local storage and thus completely remove the global state. In a non-threaded build, though, we simply leave the global state as-is, which may result in an error upon reinitializing libgit2. Fix the issue by zeroing out the variable on a shutdown, thus returning it to its initial state.
| * | global: synchronize initialization and shutdown with pthreadsPatrick Steinhardt2016-11-011-3/+17
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to initialize and tear down global data structures from different threads at once with `git_libgit2_init` and `git_libgit2_shutdown`, we race around initializing data. While we use `pthread_once` to assert that we only initilize data a single time, we actually reset the `pthread_once_t` on the last call to `git_libgit2_shutdown`. As resetting this variable is not synchronized with other threads trying to access it, this is actually racy when one thread tries to do a complete shutdown of libgit2 while another thread tries to initialize it. Fix the issue by creating a mutex which synchronizes `init_once` and the library shutdown.
* | Merge pull request #3977 from jfultz/fix-forced-branch-creation-on-bare-repoPatrick Steinhardt2016-11-041-4/+5
|\ \
| * | branch: fix forced branch creation on HEAD of a bare repoJohn Fultz2016-11-041-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code correctly detects that forced creation of a branch on a nonbare repo should not be able to overwrite a branch which is the HEAD reference. But there's no reason to prevent this on a bare repo, and in fact, git allows this. I.e., git branch -f master new_sha works on a bare repo with HEAD set to master. This change fixes that problem, and updates tests so that, for this case, both the bare and nonbare cases are checked for correct behavior.
* | | Merge pull request #3960 from ignatenkobrain/openssl-1.1.0Carlos Martín Nieto2016-11-022-25/+150
|\ \ \ | | | | | | | | add support for OpenSSL 1.1.0 for BIO filter
| * | | openssl: include OpenSSL headers only when we're buliding against itCarlos Martín Nieto2016-11-021-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | We need to include the initialisation and construction functions in all backend, so we include this header when building against SecureTransport and WinHTTP as well.
| * | | openssl: use ASN1_STRING_get0_data when compiling against 1.1Carlos Martín Nieto2016-11-022-2/+7
| | | | | | | | | | | | | | | | For older versions we can fall back on the deprecated ASN1_STRING_data.
| * | | openssl: recreate the OpenSSL 1.1 BIO interface for older versionsCarlos Martín Nieto2016-11-022-55/+134
| | | | | | | | | | | | | | | | | | | | We want to program against the interface, so recreate it when we compile against pre-1.1 versions.
| * | | add support for OpenSSL 1.1.0 for BIO filterIgor Gnatenko2016-10-121-0/+37
| |/ / | | | | | | | | | | | | Closes: https://github.com/libgit2/libgit2/issues/3959 Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
* | | pack: fix race in pack_entry_find_offsetPatrick Steinhardt2016-11-021-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In `pack_entry_find_offset`, we try to find the offset of a certain object in the pack file. To do so, we first assert if the packfile has already been opened and open it if not. Opening the packfile is guarded with a mutex, so concurrent access to this is in fact safe. What is not thread-safe though is our calculation of offsets inside the packfile. Assume two threads calling `pack_entry_find_offset` at the same time. We first calculate the offset and index location and only then determine if the pack has already been opened. If so, we re-calculate the offset and index address. Now the case for two threads: thread 1 first calculates the addresses and is subsequently suspended. The second thread will now call `pack_index_open` and initialize the pack file, calculating its addresses correctly. When the first thread is resumed now, he'll see that the pack file has already been initialized and will happily proceed with the addresses it has already calculated before the check. As the pack file was not initialized before, these addresses are bogus. Fix the issue by only calculating the addresses after having checked if the pack file is open.
* | | Merge pull request #3976 from pks-t/pks/pqueue-null-derefPatrick Steinhardt2016-11-021-2/+3
|\ \ \ | |_|/ |/| | pqueue: resolve possible NULL pointer dereference
| * | pqueue: resolve possible NULL pointer dereferencePatrick Steinhardt2016-10-281-2/+3
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `git_pqueue` struct allows being fixed in its total number of entries. In this case, we simply throw away items that are inserted into the priority queue by examining wether the new item to be inserted has a higher priority than the previous smallest one. This feature somewhat contradicts our pqueue implementation in that it is allowed to not have a comparison function. In fact, we also fail to check if the comparison function is actually set in the case where we add a new item into a fully filled fixed-size pqueue. As we cannot determine which item is the smallest item in absence of a comparison function, we fix the `NULL` pointer dereference by simply dropping all new items which are about to be inserted into a full fixed-size pqueue.
* | openssl_stream: fix typoPatrick Steinhardt2016-10-311-1/+1
|/
* Merge branch 'pr/3809'Edward Thomson2016-10-091-10/+18
|\
| * make git_diff_stats_to_buf not show 0 insertions or 0 deletionsSim Domingo2016-10-091-10/+18
| |
* | Merge pull request #3956 from pks-t/pks/object-parsing-hardeningEdward Thomson2016-10-092-4/+10
|\ \ | | | | | | Object parsing hardening
| * | commit: always initialize commit messagePatrick Steinhardt2016-10-091-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When parsing a commit, we will treat all bytes left after parsing the headers as the commit message. When no bytes are left, we leave the commit's message uninitialized. While uncommon to have a commit without message, this is the right behavior as Git unfortunately allows for empty commit messages. Given that this scenario is so uncommon, most programs acting on the commit message will never check if the message is actually set, which may lead to errors. To work around the error and not lay the burden of checking for empty commit messages to the developer, initialize the commit message with an empty string when no commit message is given.
| * | tree: validate filename and OID length when parsing objectPatrick Steinhardt2016-10-071-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | When parsing tree entries from raw object data, we do not verify that the tree entry actually has a filename as well as a valid object ID. Fix this by asserting that the filename length is non-zero as well as asserting that there are at least `GIT_OID_RAWSZ` bytes left when parsing the OID.
* | | Merge pull request #3921 from libgit2/cmn/walk-limit-enoughEdward Thomson2016-10-078-191/+301
|\ \ \ | | | | | | | | Improve revision walk preparation logic
| * | | revwalk: don't show commits that become uninteresting after being enqueuedcmn/walk-limit-enoughCarlos Martín Nieto2016-10-061-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | When we read from the list which `limit_list()` gives us, we need to check that the commit is still interesting, as it might have become uninteresting after it was added to the list.
| * | | rebase: don't ask for time sortingCarlos Martín Nieto2016-10-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | `git-rebase--merge` does not ask for time sorting, but uses the default. We now produce the same default time-ordered output as git, so make us of that since it's not always the same output as our time sorting.
| * | | revwalk: update the description for the default sortingCarlos Martín Nieto2016-10-061-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | It changed from implementation-defined to git's default sorting, as there are systems (e.g. rebase) which depend on this order. Also specify more explicitly how you can get git's "date-order".
| * | | revwalk: remove a useless enqueueing phase for topological and default sortingCarlos Martín Nieto2016-10-061-23/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | After `limit_list()` we already have the list in time-sorted order, which is what we want in the "default" case. Enqueueing into the "unsorted" list would just reverse it, and the topological sort will do its own sorting if it needs to.
| * | | revwalk: get rid of obsolete marking codeCarlos Martín Nieto2016-10-061-122/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We've now moved to code that's closer to git and produces the output during the preparation phase, so we no longer process the commits as part of generating the output. This makes a chunk of code redundant, as we're simply short-circuiting it by detecting we've processed the commits alrady.
| * | | revwalk: style changeCarlos Martín Nieto2016-10-061-4/+2
| | | | | | | | | | | | | | | | | | | | Change the condition for returning 0 more in line with that we write elsewhere in the library.
| * | | commit_list: fix the date comparison functionCarlos Martín Nieto2016-10-061-3/+8
| | | | | | | | | | | | | | | | | | | | This returns the integer-cast truth value comparing the dates. What we want instead of a (-1, 0, 1) output depending on how they compare.
| * | | revwalk: port over the topological sortingCarlos Martín Nieto2016-10-061-47/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After porting over the commit hiding and selection we were still left with mistmaching output due to the topologial sort. This ports the topological sorting code to make us match with our equivalent of `--date-order` and `--topo-order` against the output from `rev-list`.
| * | | pqueue: support not having a comparison functionCarlos Martín Nieto2016-10-061-3/+9
| | | | | | | | | | | | | | | | In this case, we simply behave like a vector.
| * | | vector, pqueue: add git_vector_reverse and git_pqueue_reverseCarlos Martín Nieto2016-10-063-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a convenience function to reverse the contents of a vector and a pqueue in-place. The pqueue function is useful in the case where we're treating it as a LIFO queue.
| * | | revwalk: get closer to gitCarlos Martín Nieto2016-10-062-43/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We had some home-grown logic to figure out which objects to show during the revision walk, but it was rather inefficient, looking over the same list multiple times to figure out when we had run out of interesting commits. We now use the lists in a smarter way. We also introduce the slop mechanism to determine when to stpo looking. When we run out of interesting objects, we continue preparing the walk for another 5 rounds in order to make it less likely that we miss objects in situations with complex graphs.
* | | | Make sure we use the `C` locale for `regcomp` on macOS.Arthur Schreiber2016-10-066-11/+22
|/ / /
* | | Merge pull request #3931 from ↵Edward Thomson2016-10-011-0/+4
|\ \ \ | | | | | | | | | | | | | | | | libgit2/ethomson/checkout_dont_calculate_oid_for_dirs checkout: don't try to calculate oid for directories
| * | | checkout: don't try to calculate oid for directoriesethomson/checkout_dont_calculate_oid_for_dirsEdward Thomson2016-09-141-0/+4
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to determine if we can safely overwrite an existing workdir item, we may need to calculate the oid for the workdir item to determine if its identical to the old side (and eligible for removal). We previously did this regardless of the type of entry in the workdir; if it was a directory, we would open(2) it and then try to read(2). The read(2) of a directory fails on many platforms, so we would treat it as if it were unmodified and continue to perform the checkout. On FreeBSD, you _can_ read(2) a directory, so this pattern failed. We would calculate an oid from the data read and determine that the directory was modified and would therefore generate a checkout conflict. This reliance on read(2) is silly (and was most likely accidentally giving us the behavior we wanted), we should be explicit about the directory test.
* | | time: Export `git_time_monotonic`vmg/timeVicent Marti2016-09-131-0/+5
| | |