1. 19 Jul, 2018 2 commits
    • smart_pkt: fix potential OOB-read when processing ng packet · 19bed3e2
      OSS-fuzz has reported a potential out-of-bounds read when processing a
      "ng" smart packet:
      
      ==1==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6310000249c0 at pc 0x000000493a92 bp 0x7ffddc882cd0 sp 0x7ffddc882480
      	READ of size 65529 at 0x6310000249c0 thread T0
      	SCARINESS: 26 (multi-byte-read-heap-buffer-overflow)
      	#0 0x493a91 in __interceptor_strchr.part.35 /src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:673
      	#1 0x813960 in ng_pkt libgit2/src/transports/smart_pkt.c:320:14
      	#2 0x810f79 in git_pkt_parse_line libgit2/src/transports/smart_pkt.c:478:9
      	#3 0x82c3c9 in git_smart__store_refs libgit2/src/transports/smart_protocol.c:47:12
      	#4 0x6373a2 in git_smart__connect libgit2/src/transports/smart.c:251:15
      	#5 0x57688f in git_remote_connect libgit2/src/remote.c:708:15
      	#6 0x52e59b in LLVMFuzzerTestOneInput /src/download_refs_fuzzer.cc:145:9
      	#7 0x52ef3f in ExecuteFilesOnyByOne(int, char**) /src/libfuzzer/afl/afl_driver.cpp:301:5
      	#8 0x52f4ee in main /src/libfuzzer/afl/afl_driver.cpp:339:12
      	#9 0x7f6c910db82f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/libc-start.c:291
      	#10 0x41d518 in _start
      
      When parsing an "ng" packet, we keep track of both the current position
      as well as the remaining length of the packet itself. But instead of
      taking care not to exceed the length, we pass the current pointer's
      position to `strchr`, which will search for a certain character until
      hitting NUL. It is thus possible to create a crafted packet which
      doesn't contain a NUL byte to trigger an out-of-bounds read.
      
      Fix the issue by instead using `memchr`, passing the remaining length as
      restriction. Furthermore, verify that we actually have enough bytes left
      to produce a match at all.
      
      OSS-Fuzz-Issue: 9406
      Patrick Steinhardt committed
    • Merge pull request #4704 from nelhage/no-pkt-pack · fa401a32
      Remove GIT_PKT_PACK entirely
      Patrick Steinhardt committed
  2. 16 Jul, 2018 1 commit
  3. 15 Jul, 2018 3 commits
  4. 14 Jul, 2018 1 commit
  5. 13 Jul, 2018 6 commits
    • ignore: improve `git_ignore_path_is_ignored` description Git analogy · 9cab93c0
      In attempt to provide adequate Git command analogy in regards to
      ignored files handling, `git_ignore_path_is_ignored` description
      mentions doing `git add .` on directory containing the file, and
      whether the file in question would be added or not - but behavior of
      the two matches for untracked files only, making the comparison
      misleading in general sense.
      
      For tracked files, Git doesn't subject them to ignore rules, so even
      if a rule applies, `git add .` would actually add the tracked file
      changes to index, while `git_ignore_path_is_ignored` would still
      consider the file being ignored (as it doesn't check the index, as
      documented).
      
      Let's provide `git check-ignore --no-index` as analogous Git command
      example instead, being more aligned with what `git_ignore_path_is_ignored`
      is about, no matter if the file in question is already tracked or not.
      
      See issue #4720 (git_ignore_path_is_ignored documentation
      misleading?, 2018-07-10)[1] for additional information.
      
      [1] https://github.com/libgit2/libgit2/issues/4720
      Igor Djordjevic committed
    • cmake: enforce C90 standard · e1a4a8eb
      While the aim of libgit2 was to conform to C90 code, we never instructed
      the compiler to enforce C90 compliance. Thus, quite a few violations
      were able to get into our code base, which have been removed with the
      previous commits. As we are now able to build libgit2 with C90 enforced,
      we can set the C_STANDARD property for our own build targets.
      
      Note that we explicitly avoid setting the C standard for our third-party
      dependencies. At least the zlib target does not build with C90 enforced,
      and we do not want to fix them by deviating from upstream. Thus we
      simply enforce no standard for them.
      Patrick Steinhardt committed
    • mbedtls: fix `inline` being used in mbedtls headers · d19381e2
      The mbedtls headers make direct use of the `inline` attribute to
      instruct the compiler to inline functions. As this function is not C90
      compliant, this can cause the compiler to error as soon as any of these
      files is included and the `-std=c90` flag is being added.
      
      The mbedtls headers declaring functions as inline always have a prelude
      which define `inline` as a macro in case it is not yet defined. Thus, we
      can easily replace their define with our own define, which simply copies
      the logic of our own `GIT_INLINE` macro.
      Patrick Steinhardt committed
    • cmake: distinguish internal and system include directories · c13e56f9
      While we want to enforce strict C90 mode, this may cause issues with
      system provided header files which are themselves not strictly
      conforming. E.g. if a system header has C++ style comments, a compiler
      in strict C90 mode would produce an error and abort the build. As the
      user most likely doesn't want to change the system header, this would
      completely break the build on such systems. One example of this is
      mbedtls, which provides such header files.
      
      The problem can be worked around by distinguishing between
      system-provided and project-provided include directories. When adding
      include directories via "-isystem" instead of "-I", the compiler will
      skip certain checks and print out less warnings. To use system includes,
      we can simply add the "SYSTEM" flag to CMake's `INCLUDE_DIRECTORIES` and
      `TARGET_INCLUDE_DIRECTORIES` functions. Note that we have to split the
      include directories into two variables because of this, as we definitely
      still want to check for all warnings produced by our own header files.
      Patrick Steinhardt committed
    • treewide: remove use of C++ style comments · 9994cd3f
      C++ style comment ("//") are not specified by the ISO C90 standard and
      thus do not conform to it. While libgit2 aims to conform to C90, we did
      not enforce it until now, which is why quite a lot of these
      non-conforming comments have snuck into our codebase. Do a tree-wide
      conversion of all C++ style comments to the supported C style comments
      to allow us enforcing strict C90 compliance in a later commit.
      Patrick Steinhardt committed
    • treewide: avoid use of `inline` attribute · f347a441
      ISO C90 does not specify the `inline` attribute, and as such we cannot
      use it in our code. While we already use `__inline` when building in
      Microsoft Visual Studio, we should also be using the `__inline__`
      attribute from GCC/Clang. Otherwise, if we're using neither MSVC nor
      GCC/Clang, we should simply avoid using `inline` at all and just define
      functions as static.
      
      This commit adjusts our own `GIT_INLINE` macro as well as the inline
      macros specified by khash and xdiff. This allows us to enable strict C90
      mode in a later commit.
      Patrick Steinhardt committed
  6. 09 Jul, 2018 1 commit
  7. 08 Jul, 2018 1 commit
  8. 06 Jul, 2018 4 commits
  9. 05 Jul, 2018 1 commit
    • delta: fix overflow when computing limit · e087c0de
      When checking whether a delta base offset and length fit into the base
      we have in memory already, we can trigger an overflow which breaks the
      check. This would subsequently result in us reading memory from out of
      bounds of the base.
      
      The issue is easily fixed by checking for overflow when adding `off` and
      `len`, thus guaranteeting that we are never indexing beyond `base_len`.
      This corresponds to the git patch 8960844a7 (check patch_delta bounds
      more carefully, 2006-04-07), which adds these overflow checks.
      
      Reported-by: Riccardo Schirone <rschiron@redhat.com>
      Patrick Steinhardt committed
  10. 30 Jun, 2018 1 commit
  11. 29 Jun, 2018 19 commits