1. 06 9月, 2017 1 次提交
    • J
      config: use a static lock_file struct · f991761e
      Jeff King 提交于
      When modifying git config, we xcalloc() a struct lock_file
      but never free it. This is necessary because the tempfile
      code (upon which the locking code is built) requires that
      the resulting struct remain valid through the life of the
      program. However, it also confuses leak-checkers like
      valgrind because only the inner "struct tempfile" is still
      reachable; no pointer to the outer lock_file is kept.
      
      Other code paths solve this by using a single static lock
      struct. We can do the same here, because we know that we'll
      only lock and modify one config file at a time (and
      assertions within the lockfile code will ensure that this
      remains the case).
      
      That removes a real leak (when we fail to free the struct
      after locking fails) as well as removes the valgrind false
      positive. It also means that doing N sequential
      config-writes will use a constant amount of memory, rather
      than leaving stale lock_files for each.
      
      Note that since "lock" is no longer a pointer, it can't be
      NULL anymore. But that's OK. We used that feature only to
      avoid calling rollback_lock_file() on an already-committed
      lock. Since the lockfile code keeps its own "active" flag,
      it's a noop to rollback an inactive lock, and we don't have
      to worry about this ourselves.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f991761e
  2. 31 7月, 2017 12 次提交
  3. 29 7月, 2017 7 次提交
    • J
      Merge branch 'jk/ssh-funny-url' into maint-2.7 · a4f234bf
      Junio C Hamano 提交于
      a4f234bf
    • J
      connect: reject paths that look like command line options · aeeb2d49
      Jeff King 提交于
      If we get a repo path like "-repo.git", we may try to invoke
      "git-upload-pack -repo.git". This is going to fail, since
      upload-pack will interpret it as a set of bogus options. But
      let's reject this before we even run the sub-program, since
      we would not want to allow any mischief with repo names that
      actually are real command-line options.
      
      You can still ask for such a path via git-daemon, but there's no
      security problem there, because git-daemon enters the repo itself
      and then passes "."  on the command line.
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      aeeb2d49
    • J
      connect: reject dashed arguments for proxy commands · 3be4cf09
      Jeff King 提交于
      If you have a GIT_PROXY_COMMAND configured, we will run it
      with the host/port on the command-line. If a URL contains a
      mischievous host like "--foo", we don't know how the proxy
      command may handle it. It's likely to break, but it may also
      do something dangerous and unwanted (technically it could
      even do something useful, but that seems unlikely).
      
      We should err on the side of caution and reject this before
      we even run the command.
      
      The hostname check matches the one we do in a similar
      circumstance for ssh. The port check is not present for ssh,
      but there it's not necessary because the syntax is "-p
      <port>", and there's no ambiguity on the parsing side.
      
      It's not clear whether you can actually get a negative port
      to the proxy here or not. Doing:
      
        git fetch git://remote:-1234/repo.git
      
      keeps the "-1234" as part of the hostname, with the default
      port of 9418. But it's a good idea to keep this check close
      to the point of running the command to make it clear that
      there's no way to circumvent it (and at worst it serves as a
      belt-and-suspenders check).
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3be4cf09
    • J
      connect: factor out "looks like command line option" check · 2491f77b
      Jeff King 提交于
      We reject hostnames that start with a dash because they may
      be confused for command-line options. Let's factor out that
      notion into a helper function, as we'll use it in more
      places. And while it's simple now, it's not clear if some
      systems might need more complex logic to handle all cases.
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2491f77b
    • J
      t5813: add test for hostname starting with dash · 2d90add5
      Jeff King 提交于
      Per the explanation in the previous patch, this should be
      (and is) rejected.
      Signed-off-by: NJeff King <peff@peff.net>
      Reviewed-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2d90add5
    • J
      connect: reject ssh hostname that begins with a dash · 820d7650
      Junio C Hamano 提交于
      When commands like "git fetch" talk with ssh://$rest_of_URL/, the
      code splits $rest_of_URL into components like host, port, etc., and
      then spawns the underlying "ssh" program by formulating argv[] array
      that has:
      
       - the path to ssh command taken from GIT_SSH_COMMAND, etc.
      
       - dashed options like '-batch' (for Tortoise), '-p <port>' as
         needed.
      
       - ssh_host, which is supposed to be the hostname parsed out of
         $rest_of_URL.
      
       - then the command to be run on the other side, e.g. git
         upload-pack.
      
      If the ssh_host ends up getting '-<anything>', the argv[] that is
      used to spawn the command becomes something like:
      
          { "ssh", "-p", "22", "-<anything>", "command", "to", "run", NULL }
      
      which obviously is bogus, but depending on the actual value of
      "<anything>", will make "ssh" parse and use it as an option.
      
      Prevent this by forbidding ssh_host that begins with a "-".
      
      Noticed-by: Joern Schneeweisz of Recurity Labs
      Reported-by: Brian at GitLab
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      Reviewed-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      820d7650
    • J
      t/lib-proto-disable: restore protocol.allow after config tests · 30c586ff
      Jeff King 提交于
      The tests for protocol.allow actually set that variable in
      the on-disk config, run a series of tests, and then never
      clean up after themselves. This means that whatever tests we
      run after have protocol.allow=never, which may influence
      their results.
      
      In most cases we either exit after running these tests, or
      do another round of test_proto(). In the latter case, this happens to
      work because:
      
        1. Tests of the GIT_ALLOW_PROTOCOL environment variable
           override the config.
      
        2. Tests of the specific config "protocol.foo.allow"
           override the protocol.allow config.
      
        3. The next round of protocol.allow tests start off by
           setting the config to a known value.
      
      However, it's a land-mine waiting to trap somebody adding
      new tests to one of the t581x test scripts. Let's make sure
      we clean up after ourselves.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      30c586ff
  4. 05 5月, 2017 19 次提交
  5. 29 3月, 2017 1 次提交