1. 19 Oct, 2018 2 commits
    • index: fix adding index entries with conflicting files · 8b6e2895
      When adding an index entry "a/b/c" while an index entry "a/b" already
      exists, git will happily remove "a/b/c" and only add the new index
      entry:
      
          $ git init test
          Initialized empty Git repository in /tmp/test.repo/test/.git/
          $ touch x
          $ git add x
          $ rm x
          $ mkdir x
          $ touch x/y
          $ git add x/y
          $ git status
          A x/y
      
      The other way round, adding an index entry "a/b" with an entry "a/b/c"
      already existing is equivalent, where git will remove "a/b/c" and add
      "a/b".
      
      In contrast, libgit2 will currently fail to add these properly and
      instead complain about the entry appearing as both a file and a
      directory. This is a programming error, though: our current code already
      tries to detect and, in the case of `git_index_add`, to automatically
      replace such index entries. Funnily enough, we already remove the
      conflicting index entries, but instead of adding the new entry we then
      bail out afterwards. This leaves callers with the worst of both worlds:
      we both remove the old entry but fail to add the new one.
      
      The root cause is weird semantics of the `has_file_name` and
      `has_dir_name` functions. While these functions only sound like they are
      responsible for detecting such conflicts, they will also already remove
      them in case where its `ok_to_replace` parameter is set. But even if we
      tell it to replace such entries, it will return an error code.
      
      Fix the error by returning success in case where the entries have been
      replaced. Fix an already existing test which tested for wrong behaviour.
      Note that the test didn't notice that the resulting tree had no entries.
      Thus it is fine to change existing behaviour here, as the previous
      result could've let to silently loosing data. Also add a new test that
      verifies behaviour in the reverse conflicting case.
      Patrick Steinhardt committed
    • index: modernize error handling of `index_insert` · 923317db
      The current error hanling of the function `index_insert` is currently
      very fragile. Instead of erroring out in case an error has happened, it
      will instead verify that no error has happened for each statement. This
      makes adding new code to that function an adventurous task.
      
      Improve the situation by converting the function to use our typical
      `goto out` pattern.
      Patrick Steinhardt committed
  2. 17 Oct, 2018 3 commits
  3. 15 Oct, 2018 3 commits
  4. 13 Oct, 2018 1 commit
  5. 12 Oct, 2018 1 commit
  6. 11 Oct, 2018 4 commits
    • Apply code review feedback · 463c21e2
      Nelson Elhage committed
    • fuzzers: add object parsing fuzzer · a1d5fd06
      Add a simple fuzzer that exercises our object parser code. The fuzzer
      is quite trivial in that it simply passes the input data directly to
      `git_object__from_raw` for each of the four object types.
      Patrick Steinhardt committed
    • object: properly propagate errors on parsing failures · 6562cdda
      When failing to parse a raw object fromits data, we free the
      partially parsed object but then fail to propagate the error to the
      caller. This may lead callers to operate on objects with invalid memory,
      which will sooner or later cause the program to segfault.
      
      Fix the issue by passing up the error code returned by `parse_raw`.
      Patrick Steinhardt committed
    • fuzzers: initialize libgit2 in standalone driver · 6956a954
      The standalone driver for libgit2's fuzzing targets makes use of
      functions from libgit2 itself. While this is totally fine to do, we need
      to make sure to always have libgit2 initialized via `git_libgit2_init`
      before we call out to any of these. While this happens in most cases as
      we call `LLVMFuzzerInitialize`, which is provided by our fuzzers and
      which right now always calls `git_libgit2_init`, one exception to this
      rule is our error path when not enough arguments have been given. In
      this case, we will call `git_vector_free_deep` without libgit2 having
      been initialized. As we did not set up our allocation functions in that
      case, this will lead to a segmentation fault.
      
      Fix the issue by always initializing and shutting down libgit2 in the
      standalone driver. Note that we cannot let this replace the
      initialization in `LLVMFuzzerInitialize`, as it is required when using
      the "real" fuzzers by LLVM without our standalone driver. It's no
      problem to call the initialization and deinitialization functions
      multiple times, though.
      Patrick Steinhardt committed
  7. 09 Oct, 2018 2 commits
  8. 07 Oct, 2018 3 commits
  9. 06 Oct, 2018 1 commit
    • ignore unsupported http authentication schemes · 475db39b
      auth_context_match returns 0 instead of -1 for unknown schemes to
      not fail in situations where some authentication schemes are supported
      and others are not.
      
      apply_credentials is adjusted to handle auth_context_match returning
      0 without producing authentication context.
      Anders Borum committed
  10. 05 Oct, 2018 12 commits
  11. 04 Oct, 2018 7 commits
  12. 03 Oct, 2018 1 commit
    • smart_pkt: do not accept callers passing in no line length · 1bc5b05c
      Right now, we simply ignore the `linelen` parameter of
      `git_pkt_parse_line` in case the caller passed in zero. But in fact, we
      never want to assume anything about the provided buffer length and
      always want the caller to pass in the available number of bytes.
      And in fact, checking all the callers, one can see that the funciton is
      never being called in case where the buffer length is zero, and thus we
      are safe to remove this check.
      Patrick Steinhardt committed