]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
14 months agowildmatch: avoid undefined behavior
Phillip Wood [Mon, 20 Mar 2023 16:10:01 +0000 (16:10 +0000)] 
wildmatch: avoid undefined behavior

The code changed in this commit is designed to check if the pattern
starts with "**/" or contains "/**/" (see 3a078dec33 (wildmatch: fix
"**" special case, 2013-01-01)). Unfortunately when the pattern begins
with "**/" `prev_p = p - 2` is evaluated when `p` points to the second
"*" and so the subtraction is undefined according to section 6.5.6 of
the C standard because the result does not point within the same object
as `p`. Fix this by avoiding the subtraction unless it is well defined.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 months agowildmatch: fix exponential behavior
Phillip Wood [Mon, 20 Mar 2023 16:10:00 +0000 (16:10 +0000)] 
wildmatch: fix exponential behavior

When dowild() cannot match a '*' or '/**/' wildcard then it must return
WM_ABORT_TO_STARSTAR or WM_ABORT_ALL respectively. Failure to observe
this results in unnecessary backtracking and the time taken for a failed
match increases exponentially with the number of wildcards in the
pattern [1]. Unfortunately in some instances dowild() returns WM_NOMATCH
for a failed match resulting in long match times for patterns containing
multiple wildcards as can be seen in the following benchmark.
(Note that the timings in the Benchmark 1 are really measuring the time
to execute test-tool rather than the time to match the pattern)

Benchmark 1: t/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a"
  Time (mean ± σ):      22.8 ms ±   1.7 ms    [User: 12.1 ms, System: 10.6 ms]
  Range (min … max):    19.4 ms …  26.9 ms    113 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: t/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a*a*a*a*a*a*a*a*a"
  Time (mean ± σ):      5.244 s ±  0.228 s    [User: 5.229 s, System: 0.010 s]
  Range (min … max):    4.969 s …  5.707 s    10 runs

  Warning: Ignoring non-zero exit code.

Summary
  't/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a"' ran
  230.37 ± 20.04 times faster than 't/helper/test-tool wildmatch wildmatch aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "*a*a*a*a*a*a*a*a*a"'

The security implications are limited as it only affects operations that
are potentially DoS vectors. For example by creating a blob containing
such a pattern a malicious user can exploit this behavior to use large
amounts of CPU time on a remote server by pushing the blob and then
creating a new clone with --filter=sparse:oid. However this filter type
is usually disabled as it is known to consume large amounts of CPU time
even without this bug.

The WM_MATCH changed in the first hunk of this patch comes from the
original implementation imported from rsync in 5230f605e1 (Import
wildmatch from rsync, 2012-10-15). Compared to the others converted here
it is fairly harmless as it only triggers at the end of the pattern and
so will only cause a single unnecessary backtrack. The others introduced
by 6f1a31f0aa (wildmatch: advance faster in <asterisk> + <literal>
patterns, 2013-01-01) and 46983441ae (wildmatch: make a special case for
"*/" with FNM_PATHNAME, 2013-01-01) are more pernicious and will cause
exponential behavior.

A new test is added to protect against future regressions.

[1] https://research.swtch.com/glob

Helped-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoPrepare for 2.39.3 just in case
Junio C Hamano [Tue, 14 Feb 2023 22:15:23 +0000 (14:15 -0800)] 
Prepare for 2.39.3 just in case

Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 months agoMerge branch 'sk/remove-duplicate-includes' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:57 +0000 (14:15 -0800)] 
Merge branch 'sk/remove-duplicate-includes' into maint-2.39

Code clean-up.

* sk/remove-duplicate-includes:
  git: remove duplicate includes

15 months agoMerge branch 'rs/clarify-error-in-write-loose-object' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:57 +0000 (14:15 -0800)] 
Merge branch 'rs/clarify-error-in-write-loose-object' into maint-2.39

Code clean-up.

* rs/clarify-error-in-write-loose-object:
  object-file: inline write_buffer()

15 months agoMerge branch 'rs/reflog-expiry-cleanup' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:56 +0000 (14:15 -0800)] 
Merge branch 'rs/reflog-expiry-cleanup' into maint-2.39

Code clean-up.

* rs/reflog-expiry-cleanup:
  reflog: clear leftovers in reflog_expiry_cleanup()

15 months agoMerge branch 'rs/clear-commit-marks-cleanup' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:56 +0000 (14:15 -0800)] 
Merge branch 'rs/clear-commit-marks-cleanup' into maint-2.39

Code clean-up.

* rs/clear-commit-marks-cleanup:
  commit: skip already cleared parents in clear_commit_marks_1()

15 months agoMerge branch 'rs/am-parse-options-cleanup' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:56 +0000 (14:15 -0800)] 
Merge branch 'rs/am-parse-options-cleanup' into maint-2.39

Code clean-up.

* rs/am-parse-options-cleanup:
  am: don't pass strvec to apply_parse_options()

15 months agoMerge branch 'jk/server-supports-v2-cleanup' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:55 +0000 (14:15 -0800)] 
Merge branch 'jk/server-supports-v2-cleanup' into maint-2.39

Code clean-up.

* jk/server-supports-v2-cleanup:
  server_supports_v2(): use a separate function for die_on_error

15 months agoMerge branch 'jk/unused-post-2.39' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:55 +0000 (14:15 -0800)] 
Merge branch 'jk/unused-post-2.39' into maint-2.39

Code clean-up around unused function parameters.

* jk/unused-post-2.39:
  userdiff: mark unused parameter in internal callback
  list-objects-filter: mark unused parameters in virtual functions
  diff: mark unused parameters in callbacks
  xdiff: mark unused parameter in xdl_call_hunk_func()
  xdiff: drop unused parameter in def_ff()
  ws: drop unused parameter from ws_blank_line()
  list-objects: drop process_gitlink() function
  blob: drop unused parts of parse_blob_buffer()
  ls-refs: use repository parameter to iterate refs

15 months agoMerge branch 'rj/branch-copy-and-rename' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:55 +0000 (14:15 -0800)] 
Merge branch 'rj/branch-copy-and-rename' into maint-2.39

Fix a pair of bugs in 'git branch'.

* rj/branch-copy-and-rename:
  branch: force-copy a branch to itself via @{-1} is a no-op

15 months agoMerge branch 'rs/t3920-crlf-eating-grep-fix' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:54 +0000 (14:15 -0800)] 
Merge branch 'rs/t3920-crlf-eating-grep-fix' into maint-2.39

Test fix.

* rs/t3920-crlf-eating-grep-fix:
  t3920: support CR-eating grep

15 months agoMerge branch 'js/t3920-shell-and-or-fix' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:54 +0000 (14:15 -0800)] 
Merge branch 'js/t3920-shell-and-or-fix' into maint-2.39

Test fix.

* js/t3920-shell-and-or-fix:
  t3920: don't ignore errors of more than one command with `|| true`

15 months agoMerge branch 'ab/t4023-avoid-losing-exit-status-of-diff' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:54 +0000 (14:15 -0800)] 
Merge branch 'ab/t4023-avoid-losing-exit-status-of-diff' into maint-2.39

Test fix.

* ab/t4023-avoid-losing-exit-status-of-diff:
  t4023: fix ignored exit codes of git

15 months agoMerge branch 'ab/t7600-avoid-losing-exit-status-of-git' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:53 +0000 (14:15 -0800)] 
Merge branch 'ab/t7600-avoid-losing-exit-status-of-git' into maint-2.39

Test fix.

* ab/t7600-avoid-losing-exit-status-of-git:
  t7600: don't ignore "rev-parse" exit code in helper

15 months agoMerge branch 'ab/t5314-avoid-losing-exit-status' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:53 +0000 (14:15 -0800)] 
Merge branch 'ab/t5314-avoid-losing-exit-status' into maint-2.39

Test fix.

* ab/t5314-avoid-losing-exit-status:
  t5314: check exit code of "git"

15 months agoMerge branch 'rs/plug-pattern-list-leak-in-lof' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:53 +0000 (14:15 -0800)] 
Merge branch 'rs/plug-pattern-list-leak-in-lof' into maint-2.39

Leak fix.

* rs/plug-pattern-list-leak-in-lof:
  list-objects-filter: plug pattern_list leak

15 months agoMerge branch 'rs/t4205-do-not-exit-in-test-script' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:53 +0000 (14:15 -0800)] 
Merge branch 'rs/t4205-do-not-exit-in-test-script' into maint-2.39

Test fix.

* rs/t4205-do-not-exit-in-test-script:
  t4205: don't exit test script on failure

15 months agoMerge branch 'jc/doc-checkout-b' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:52 +0000 (14:15 -0800)] 
Merge branch 'jc/doc-checkout-b' into maint-2.39

Clarify how "checkout -b/-B" and "git branch [-f]" are similar but
different in the documentation.

* jc/doc-checkout-b:
  checkout: document -b/-B to highlight the differences from "git branch"

15 months agoMerge branch 'jc/doc-branch-update-checked-out-branch' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:52 +0000 (14:15 -0800)] 
Merge branch 'jc/doc-branch-update-checked-out-branch' into maint-2.39

Document that "branch -f <branch>" disables only the safety to
avoid recreating an existing branch.

* jc/doc-branch-update-checked-out-branch:
  branch: document `-f` and linked worktree behaviour

15 months agoMerge branch 'rs/ls-tree-path-expansion-fix' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:52 +0000 (14:15 -0800)] 
Merge branch 'rs/ls-tree-path-expansion-fix' into maint-2.39

"git ls-tree --format='%(path) %(path)' $tree $path" showed the
path three times, which has been corrected.

* rs/ls-tree-path-expansion-fix:
  ls-tree: remove dead store and strbuf for quote_c_style()
  ls-tree: fix expansion of repeated %(path)

15 months agoMerge branch 'pb/doc-orig-head' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:51 +0000 (14:15 -0800)] 
Merge branch 'pb/doc-orig-head' into maint-2.39

Document ORIG_HEAD a bit more.

* pb/doc-orig-head:
  git-rebase.txt: add a note about 'ORIG_HEAD' being overwritten
  revisions.txt: be explicit about commands writing 'ORIG_HEAD'
  git-merge.txt: mention 'ORIG_HEAD' in the Description
  git-reset.txt: mention 'ORIG_HEAD' in the Description
  git-cherry-pick.txt: do not use 'ORIG_HEAD' in example

15 months agoMerge branch 'es/hooks-and-local-env' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:51 +0000 (14:15 -0800)] 
Merge branch 'es/hooks-and-local-env' into maint-2.39

Doc update for environment variables set when hooks are invoked.

* es/hooks-and-local-env:
  githooks: discuss Git operations in foreign repositories

15 months agoMerge branch 'ws/single-file-cone' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:51 +0000 (14:15 -0800)] 
Merge branch 'ws/single-file-cone' into maint-2.39

The logic to see if we are using the "cone" mode by checking the
sparsity patterns has been tightened to avoid mistaking a pattern
that names a single file as specifying a cone.

* ws/single-file-cone:
  dir: check for single file cone patterns

15 months agoMerge branch 'jk/ext-diff-with-relative' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:50 +0000 (14:15 -0800)] 
Merge branch 'jk/ext-diff-with-relative' into maint-2.39

"git diff --relative" did not mix well with "git diff --ext-diff",
which has been corrected.

* jk/ext-diff-with-relative:
  diff: drop "name" parameter from prepare_temp_file()
  diff: clean up external-diff argv setup
  diff: use filespec path to set up tempfiles for ext-diff

15 months agoMerge branch 'ab/bundle-wo-args' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:50 +0000 (14:15 -0800)] 
Merge branch 'ab/bundle-wo-args' into maint-2.39

Fix to a small regression in 2.38 days.

* ab/bundle-wo-args:
  bundle <cmd>: have usage_msg_opt() note the missing "<file>"
  builtin/bundle.c: remove superfluous "newargc" variable
  bundle: don't segfault on "git bundle <subcmd>"

15 months agoMerge branch 'ps/fsync-refs-fix' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:50 +0000 (14:15 -0800)] 
Merge branch 'ps/fsync-refs-fix' into maint-2.39

Fix the sequence to fsync $GIT_DIR/packed-refs file that forgot to
flush its output to the disk..

* ps/fsync-refs-fix:
  refs: fix corruption by not correctly syncing packed-refs to disk

15 months agoMerge branch 'lk/line-range-parsing-fix' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:49 +0000 (14:15 -0800)] 
Merge branch 'lk/line-range-parsing-fix' into maint-2.39

When given a pattern that matches an empty string at the end of a
line, the code to parse the "git diff" line-ranges fell into an
infinite loop, which has been corrected.

* lk/line-range-parsing-fix:
  line-range: fix infinite loop bug with '$' regex

15 months agoMerge branch 'rs/use-enhanced-bre-on-macos' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:49 +0000 (14:15 -0800)] 
Merge branch 'rs/use-enhanced-bre-on-macos' into maint-2.39

Newer regex library macOS stopped enabling GNU-like enhanced BRE,
where '\(A\|B\)' works as alternation, unless explicitly asked with
the REG_ENHANCED flag.  "git grep" now can be compiled to do so, to
retain the old behaviour.

* rs/use-enhanced-bre-on-macos:
  use enhanced basic regular expressions on macOS

15 months agoMerge branch 'jk/curl-avoid-deprecated-api' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:49 +0000 (14:15 -0800)] 
Merge branch 'jk/curl-avoid-deprecated-api' into maint-2.39

Deal with a few deprecation warning from cURL library.

* jk/curl-avoid-deprecated-api:
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT

15 months agoMerge branch 'jk/avoid-redef-system-functions' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:49 +0000 (14:15 -0800)] 
Merge branch 'jk/avoid-redef-system-functions' into maint-2.39

The jk/avoid-redef-system-functions-2.30 topic pre-merged for more
recent codebase.

* jk/avoid-redef-system-functions:

15 months agoMerge branch 'jk/avoid-redef-system-functions-2.30' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:47 +0000 (14:15 -0800)] 
Merge branch 'jk/avoid-redef-system-functions-2.30' into maint-2.39

Redefining system functions for a few functions did not follow our
usual "implement git_foo() and #define foo(args) git_foo(args)"
pattern, which has broken build for some folks.

* jk/avoid-redef-system-functions-2.30:
  git-compat-util: undefine system names before redeclaring them
  git-compat-util: avoid redefining system function names

15 months agoMerge branch 'tb/ci-concurrency' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:46 +0000 (14:15 -0800)] 
Merge branch 'tb/ci-concurrency' into maint-2.39

Avoid unnecessary builds in CI, with settings configured in
ci-config.

* tb/ci-concurrency:
  ci: avoid unnecessary builds

15 months agoMerge branch 'cw/ci-whitespace' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:45 +0000 (14:15 -0800)] 
Merge branch 'cw/ci-whitespace' into maint-2.39

CI updates.  We probably want a clean-up to move the long shell
script embedded in yaml file into a separate file, but that can
come later.

* cw/ci-whitespace:
  ci (check-whitespace): move to actions/checkout@v3
  ci (check-whitespace): add links to job output
  ci (check-whitespace): suggest fixes for errors

15 months agoMerge branch 'js/ci-disable-cmake-by-default' into maint-2.39
Junio C Hamano [Tue, 14 Feb 2023 22:15:45 +0000 (14:15 -0800)] 
Merge branch 'js/ci-disable-cmake-by-default' into maint-2.39

Stop running win+VS build by default.

* js/ci-disable-cmake-by-default:
  ci: only run win+VS build & tests in Git for Windows' fork

16 months agoGit 2.39.2 v2.39.2
Johannes Schindelin [Mon, 6 Feb 2023 08:43:41 +0000 (09:43 +0100)] 
Git 2.39.2

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.38.4
Johannes Schindelin [Mon, 6 Feb 2023 08:43:39 +0000 (09:43 +0100)] 
Sync with 2.38.4

* maint-2.38:
  Git 2.38.4
  Git 2.37.6
  Git 2.36.5
  Git 2.35.7
  Git 2.34.7
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
  Git 2.33.7
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.38.4 v2.38.4
Johannes Schindelin [Mon, 6 Feb 2023 08:43:30 +0000 (09:43 +0100)] 
Git 2.38.4

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.37.6
Johannes Schindelin [Mon, 6 Feb 2023 08:43:28 +0000 (09:43 +0100)] 
Sync with 2.37.6

* maint-2.37:
  Git 2.37.6
  Git 2.36.5
  Git 2.35.7
  Git 2.34.7
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
  Git 2.33.7
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.37.6 v2.37.6
Johannes Schindelin [Mon, 6 Feb 2023 08:38:32 +0000 (09:38 +0100)] 
Git 2.37.6

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.36.5
Johannes Schindelin [Mon, 6 Feb 2023 08:38:31 +0000 (09:38 +0100)] 
Sync with 2.36.5

* maint-2.36:
  Git 2.36.5
  Git 2.35.7
  Git 2.34.7
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
  Git 2.33.7
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.36.5 v2.36.5
Johannes Schindelin [Mon, 6 Feb 2023 08:37:53 +0000 (09:37 +0100)] 
Git 2.36.5

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.35.7
Johannes Schindelin [Mon, 6 Feb 2023 08:37:52 +0000 (09:37 +0100)] 
Sync with 2.35.7

* maint-2.35:
  Git 2.35.7
  Git 2.34.7
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
  Git 2.33.7
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.35.7 v2.35.7
Johannes Schindelin [Mon, 6 Feb 2023 08:29:45 +0000 (09:29 +0100)] 
Git 2.35.7

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.34.7
Johannes Schindelin [Mon, 6 Feb 2023 08:29:44 +0000 (09:29 +0100)] 
Sync with 2.34.7

* maint-2.34:
  Git 2.34.7
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
  Git 2.33.7
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.34.7 v2.34.7
Johannes Schindelin [Mon, 6 Feb 2023 08:29:17 +0000 (09:29 +0100)] 
Git 2.34.7

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.33.7
Johannes Schindelin [Mon, 6 Feb 2023 08:29:16 +0000 (09:29 +0100)] 
Sync with 2.33.7

* maint-2.33:
  Git 2.33.7
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoMerge branch 'jk/curl-avoid-deprecated-api'
Junio C Hamano [Fri, 20 Jan 2023 23:36:21 +0000 (15:36 -0800)] 
Merge branch 'jk/curl-avoid-deprecated-api'

Deal with a few deprecation warning from cURL library.

* jk/curl-avoid-deprecated-api:
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT

16 months agohttp: support CURLOPT_PROTOCOLS_STR
Jeff King [Tue, 17 Jan 2023 03:04:48 +0000 (22:04 -0500)] 
http: support CURLOPT_PROTOCOLS_STR

The CURLOPT_PROTOCOLS (and matching CURLOPT_REDIR_PROTOCOLS) flag was
deprecated in curl 7.85.0, and using it generate compiler warnings as of
curl 7.87.0. The path forward is to use CURLOPT_PROTOCOLS_STR, but we
can't just do so unilaterally, as it was only introduced less than a
year ago in 7.85.0.

Until that version becomes ubiquitous, we have to either disable the
deprecation warning or conditionally use the "STR" variant on newer
versions of libcurl. This patch switches to the new variant, which is
nice for two reasons:

  - we don't have to worry that silencing curl's deprecation warnings
    might cause us to miss other more useful ones

  - we'd eventually want to move to the new variant anyway, so this gets
    us set up (albeit with some extra ugly boilerplate for the
    conditional)

There are a lot of ways to split up the two cases. One way would be to
abstract the storage type (strbuf versus a long), how to append
(strbuf_addstr vs bitwise OR), how to initialize, which CURLOPT to use,
and so on. But the resulting code looks pretty magical:

  GIT_CURL_PROTOCOL_TYPE allowed = GIT_CURL_PROTOCOL_TYPE_INIT;
  if (...http is allowed...)
GIT_CURL_PROTOCOL_APPEND(&allowed, "http", CURLOPT_HTTP);

and you end up with more "#define GIT_CURL_PROTOCOL_TYPE" macros than
actual code.

On the other end of the spectrum, we could just implement two separate
functions, one that handles a string list and one that handles bits. But
then we end up repeating our list of protocols (http, https, ftp, ftp).

This patch takes the middle ground. The run-time code is always there to
handle both types, and we just choose which one to feed to curl.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agohttp: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
Jeff King [Tue, 17 Jan 2023 03:04:44 +0000 (22:04 -0500)] 
http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION

The IOCTLFUNCTION option has been deprecated, and generates a compiler
warning in recent versions of curl. We can switch to using SEEKFUNCTION
instead. It was added in 2008 via curl 7.18.0; our INSTALL file already
indicates we require at least curl 7.19.4.

But there's one catch: curl says we should use CURL_SEEKFUNC_{OK,FAIL},
and those didn't arrive until 7.19.5. One workaround would be to use a
bare 0/1 here (or define our own macros).  But let's just bump the
minimum required version to 7.19.5. That version is only a minor version
bump from our existing requirement, and is only a 2 month time bump for
versions that are almost 13 years old. So it's not likely that anybody
cares about the distinction.

Switching means we have to rewrite the ioctl functions into seek
functions. In some ways they are simpler (seeking is the only
operation), but in some ways more complex (the ioctl allowed only a full
rewind, but now we can seek to arbitrary offsets).

Curl will only ever use SEEK_SET (per their documentation), so I didn't
bother implementing anything else, since it would naturally be
completely untested. This seems unlikely to change, but I added an
assertion just in case.

Likewise, I doubt curl will ever try to seek outside of the buffer sizes
we've told it, but I erred on the defensive side here, rather than do an
out-of-bounds read.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agohttp-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
Jeff King [Tue, 17 Jan 2023 03:04:38 +0000 (22:04 -0500)] 
http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT

The two options do exactly the same thing, but the latter has been
deprecated and in recent versions of curl may produce a compiler
warning. Since the UPLOAD form is available everywhere (it was
introduced in the year 2000 by curl 7.1), we can just switch to it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoGit 2.33.7 v2.33.7
Johannes Schindelin [Mon, 6 Feb 2023 08:25:58 +0000 (09:25 +0100)] 
Git 2.33.7

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.32.6
Johannes Schindelin [Mon, 6 Feb 2023 08:25:56 +0000 (09:25 +0100)] 
Sync with 2.32.6

* maint-2.32:
  Git 2.32.6
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.32.6 v2.32.6
Johannes Schindelin [Mon, 6 Feb 2023 08:25:09 +0000 (09:25 +0100)] 
Git 2.32.6

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.31.7
Johannes Schindelin [Mon, 6 Feb 2023 08:25:08 +0000 (09:25 +0100)] 
Sync with 2.31.7

* maint-2.31:
  Git 2.31.7
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.31.7 v2.31.7
Johannes Schindelin [Mon, 6 Feb 2023 08:24:07 +0000 (09:24 +0100)] 
Git 2.31.7

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoSync with 2.30.8
Johannes Schindelin [Mon, 6 Feb 2023 08:24:06 +0000 (09:24 +0100)] 
Sync with 2.30.8

* maint-2.30:
  Git 2.30.8
  apply: fix writing behind newly created symbolic links
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoGit 2.30.8 v2.30.8
Junio C Hamano [Fri, 3 Feb 2023 22:58:10 +0000 (14:58 -0800)] 
Git 2.30.8

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoMerge branch 'ps/apply-beyond-symlink' into maint-2.30
Junio C Hamano [Fri, 3 Feb 2023 22:57:27 +0000 (14:57 -0800)] 
Merge branch 'ps/apply-beyond-symlink' into maint-2.30

Fix a vulnerability (CVE-2023-23946) that allows crafted input to trick
`git apply` into writing files outside of the working tree.

* ps/apply-beyond-symlink:
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
16 months agoMerge branch 'tb/clone-local-symlinks' into maint-2.30
Taylor Blau [Wed, 25 Jan 2023 19:58:38 +0000 (14:58 -0500)] 
Merge branch 'tb/clone-local-symlinks' into maint-2.30

Resolve a security vulnerability (CVE-2023-22490) where `clone_local()`
is used in conjunction with non-local transports, leading to arbitrary
path exfiltration.

* tb/clone-local-symlinks:
  dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
  clone: delay picking a transport until after get_repo_path()
  t5619: demonstrate clone_local() with ambiguous transport

16 months agoapply: fix writing behind newly created symbolic links
Patrick Steinhardt [Thu, 2 Feb 2023 10:54:34 +0000 (11:54 +0100)] 
apply: fix writing behind newly created symbolic links

When writing files git-apply(1) initially makes sure that none of the
files it is about to create are behind a symlink:

```
 $ git init repo
 Initialized empty Git repository in /tmp/repo/.git/
 $ cd repo/
 $ ln -s dir symlink
 $ git apply - <<EOF
 diff --git a/symlink/file b/symlink/file
 new file mode 100644
 index 0000000..e69de29
 EOF
 error: affected file 'symlink/file' is beyond a symbolic link
```

This safety mechanism is crucial to ensure that we don't write outside
of the repository's working directory. It can be fooled though when the
patch that is being applied creates the symbolic link in the first
place, which can lead to writing files in arbitrary locations.

Fix this by checking whether the path we're about to create is
beyond a symlink or not. Tightening these checks like this should be
fine as we already have these precautions in Git as explained
above. Ideally, we should update the check we do up-front before
starting to reflect the computed changes to the working tree so that
we catch this case as well, but as part of embargoed security work,
adding an equivalent check just before we try to write out a file
should serve us well as a reasonable first step.

Digging back into history shows that this vulnerability has existed
since at least Git v2.9.0. As Git v2.8.0 and older don't build on my
system anymore I cannot tell whether older versions are affected, as
well.

Reported-by: Joern Schneeweisz <jschneeweisz@gitlab.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agodir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS
Taylor Blau [Wed, 25 Jan 2023 00:43:51 +0000 (19:43 -0500)] 
dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS

When using the dir_iterator API, we first stat(2) the base path, and
then use that as a starting point to enumerate the directory's contents.

If the directory contains symbolic links, we will immediately die() upon
encountering them without the `FOLLOW_SYMLINKS` flag. The same is not
true when resolving the top-level directory, though.

As explained in a previous commit, this oversight in 6f054f9fb3
(builtin/clone.c: disallow `--local` clones with symlinks, 2022-07-28)
can be used as an attack vector to include arbitrary files on a victim's
filesystem from outside of the repository.

Prevent resolving top-level symlinks unless the FOLLOW_SYMLINKS flag is
given, which will cause clones of a repository with a symlink'd
"$GIT_DIR/objects" directory to fail.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoclone: delay picking a transport until after get_repo_path()
Taylor Blau [Wed, 25 Jan 2023 00:43:48 +0000 (19:43 -0500)] 
clone: delay picking a transport until after get_repo_path()

In the previous commit, t5619 demonstrates an issue where two calls to
`get_repo_path()` could trick Git into using its local clone mechanism
in conjunction with a non-local transport.

That sequence is:

 - the starting state is that the local path https:/example.com/foo is a
   symlink that points to ../../../.git/modules/foo. So it's dangling.

 - get_repo_path() sees that no such path exists (because it's
   dangling), and thus we do not canonicalize it into an absolute path

 - because we're using --separate-git-dir, we create .git/modules/foo.
   Now our symlink is no longer dangling!

 - we pass the url to transport_get(), which sees it as an https URL.

 - we call get_repo_path() again, on the url. This second call was
   introduced by f38aa83f9a (use local cloning if insteadOf makes a
   local URL, 2014-07-17). The idea is that we want to pull the url
   fresh from the remote.c API, because it will apply any aliases.

And of course now it sees that there is a local file, which is a
mismatch with the transport we already selected.

The issue in the above sequence is calling `transport_get()` before
deciding whether or not the repository is indeed local, and not passing
in an absolute path if it is local.

This is reminiscent of a similar bug report in [1], where it was
suggested to perform the `insteadOf` lookup earlier. Taking that
approach may not be as straightforward, since the intent is to store the
original URL in the config, but to actually fetch from the insteadOf
one, so conflating the two early on is a non-starter.

Note: we pass the path returned by `get_repo_path(remote->url[0])`,
which should be the same as `repo_name` (aside from any `insteadOf`
rewrites).

We *could* pass `absolute_pathdup()` of the same argument, which
86521acaca (Bring local clone's origin URL in line with that of a remote
clone, 2008-09-01) indicates may differ depending on the presence of
".git/" for a non-bare repo. That matters for forming relative submodule
paths, but doesn't matter for the second call, since we're just feeding
it to the transport code, which is fine either way.

[1]: https://lore.kernel.org/git/CAMoD=Bi41mB3QRn3JdZL-FGHs4w3C2jGpnJB-CqSndO7FMtfzA@mail.gmail.com/

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agot5619: demonstrate clone_local() with ambiguous transport
Taylor Blau [Wed, 25 Jan 2023 00:43:45 +0000 (19:43 -0500)] 
t5619: demonstrate clone_local() with ambiguous transport

When cloning a repository, Git must determine (a) what transport
mechanism to use, and (b) whether or not the clone is local.

Since f38aa83f9a (use local cloning if insteadOf makes a local URL,
2014-07-17), the latter check happens after the remote has been
initialized, and references the remote's URL instead of the local path.
This is done to make it possible for a `url.<base>.insteadOf` rule to
convert a remote URL into a local one, in which case the `clone_local()`
mechanism should be used.

However, with a specially crafted repository, Git can be tricked into
using a non-local transport while still setting `is_local` to "1" and
using the `clone_local()` optimization. The below test case
demonstrates such an instance, and shows that it can be used to include
arbitrary (known) paths in the working copy of a cloned repository on a
victim's machine[^1], even if local file clones are forbidden by
`protocol.file.allow`.

This happens in a few parts:

 1. We first call `get_repo_path()` to see if the remote is a local
    path. If it is, we replace the repo name with its absolute path.

 2. We then call `transport_get()` on the repo name and decide how to
    access it. If it was turned into an absolute path in the previous
    step, then we should always treat it like a file.

 3. We use `get_repo_path()` again, and set `is_local` as appropriate.
    But it's already too late to rewrite the repo name as an absolute
    path, since we've already fed it to the transport code.

The attack works by including a submodule whose URL corresponds to a
path on disk. In the below example, the repository "sub" is reachable
via the dumb HTTP protocol at (something like):

    http://127.0.0.1:NNNN/dumb/sub.git

However, the path "http:/127.0.0.1:NNNN/dumb" (that is, a top-level
directory called "http:", then nested directories "127.0.0.1:NNNN", and
"dumb") exists within the repository, too.

To determine this, it first picks the appropriate transport, which is
dumb HTTP. It then uses the remote's URL in order to determine whether
the repository exists locally on disk. However, the malicious repository
also contains an embedded stub repository which is the target of a
symbolic link at the local path corresponding to the "sub" repository on
disk (i.e., there is a symbolic link at "http:/127.0.0.1/dumb/sub.git",
pointing to the stub repository via ".git/modules/sub/../../../repo").

This stub repository fools Git into thinking that a local repository
exists at that URL and thus can be cloned locally. The affected call is
in `get_repo_path()`, which in turn calls `get_repo_path_1()`, which
locates a valid repository at that target.

This then causes Git to set the `is_local` variable to "1", and in turn
instructs Git to clone the repository using its local clone optimization
via the `clone_local()` function.

The exploit comes into play because the stub repository's top-level
"$GIT_DIR/objects" directory is a symbolic link which can point to an
arbitrary path on the victim's machine. `clone_local()` resolves the
top-level "objects" directory through a `stat(2)` call, meaning that we
read through the symbolic link and copy or hardlink the directory
contents at the destination of the link.

In other words, we can get steps (1) and (3) to disagree by leveraging
the dangling symlink to pick a non-local transport in the first step,
and then set is_local to "1" in the third step when cloning with
`--separate-git-dir`, which makes the symlink non-dangling.

This can result in data-exfiltration on the victim's machine when
sensitive data is at a known path (e.g., "/home/$USER/.ssh").

The appropriate fix is two-fold:

 - Resolve the transport later on (to avoid using the local
   clone optimization with a non-local transport).

 - Avoid reading through the top-level "objects" directory when
   (correctly) using the clone_local() optimization.

This patch merely demonstrates the issue. The following two patches will
implement each part of the above fix, respectively.

[^1]: Provided that any target directory does not contain symbolic
  links, in which case the changes from 6f054f9fb3 (builtin/clone.c:
  disallow `--local` clones with symlinks, 2022-07-28) will abort the
  clone.

Reported-by: yvvdwf <yvvdwf@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoSync with maint-2.38
Junio C Hamano [Thu, 19 Jan 2023 21:49:08 +0000 (13:49 -0800)] 
Sync with maint-2.38

* maint-2.38:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.37
Junio C Hamano [Thu, 19 Jan 2023 21:48:26 +0000 (13:48 -0800)] 
Sync with maint-2.37

* maint-2.37:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.36
Junio C Hamano [Thu, 19 Jan 2023 21:48:17 +0000 (13:48 -0800)] 
Sync with maint-2.36

* maint-2.36:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.35
Junio C Hamano [Thu, 19 Jan 2023 21:48:08 +0000 (13:48 -0800)] 
Sync with maint-2.35

* maint-2.35:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.34
Junio C Hamano [Thu, 19 Jan 2023 21:48:00 +0000 (13:48 -0800)] 
Sync with maint-2.34

* maint-2.34:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.33
Junio C Hamano [Thu, 19 Jan 2023 21:47:42 +0000 (13:47 -0800)] 
Sync with maint-2.33

* maint-2.33:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.32
Junio C Hamano [Thu, 19 Jan 2023 21:46:04 +0000 (13:46 -0800)] 
Sync with maint-2.32

* maint-2.32:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.31
Junio C Hamano [Thu, 19 Jan 2023 21:45:37 +0000 (13:45 -0800)] 
Sync with maint-2.31

* maint-2.31:
  attr: adjust a mismatched data type

16 months agoSync with maint-2.30
Junio C Hamano [Thu, 19 Jan 2023 21:45:23 +0000 (13:45 -0800)] 
Sync with maint-2.30

* maint-2.30:
  attr: adjust a mismatched data type

16 months agoattr: adjust a mismatched data type
Johannes Schindelin [Thu, 12 Jan 2023 00:05:02 +0000 (01:05 +0100)] 
attr: adjust a mismatched data type

On platforms where `size_t` does not have the same width as `unsigned
long`, passing a pointer to the former when a pointer to the latter is
expected can lead to problems.

Windows and 32-bit Linux are among the affected platforms.

In this instance, we want to store the size of the blob that was read in
that variable. However, `read_blob_data_from_index()` passes that
pointer to `read_object_file()` which expects an `unsigned long *`.
Which means that on affected platforms, the variable is not fully
populated and part of its value is left uninitialized. (On Big-Endian
platforms, this problem would be even worse.)

The consequence is that depending on the uninitialized memory's
contents, we may erroneously reject perfectly fine attributes.

Let's address this by passing a pointer to a variable of the expected
data type.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agocheckout: document -b/-B to highlight the differences from "git branch"
Junio C Hamano [Thu, 19 Jan 2023 17:12:41 +0000 (09:12 -0800)] 
checkout: document -b/-B to highlight the differences from "git branch"

The existing text read as if "git checkout -b/-B name" were
equivalent to "git branch [-f] name", which clearly was not
what we wanted to say.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agobranch: document `-f` and linked worktree behaviour
Junio C Hamano [Thu, 19 Jan 2023 07:23:46 +0000 (23:23 -0800)] 
branch: document `-f` and linked worktree behaviour

"git branch -f name start" forces to recreate the named branch, but
the forcing does not defeat the "do not touch a branch that is
checked out elsewhere" safety valve.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agohttp: support CURLOPT_PROTOCOLS_STR
Jeff King [Tue, 17 Jan 2023 03:04:48 +0000 (22:04 -0500)] 
http: support CURLOPT_PROTOCOLS_STR

The CURLOPT_PROTOCOLS (and matching CURLOPT_REDIR_PROTOCOLS) flag was
deprecated in curl 7.85.0, and using it generate compiler warnings as of
curl 7.87.0. The path forward is to use CURLOPT_PROTOCOLS_STR, but we
can't just do so unilaterally, as it was only introduced less than a
year ago in 7.85.0.

Until that version becomes ubiquitous, we have to either disable the
deprecation warning or conditionally use the "STR" variant on newer
versions of libcurl. This patch switches to the new variant, which is
nice for two reasons:

  - we don't have to worry that silencing curl's deprecation warnings
    might cause us to miss other more useful ones

  - we'd eventually want to move to the new variant anyway, so this gets
    us set up (albeit with some extra ugly boilerplate for the
    conditional)

There are a lot of ways to split up the two cases. One way would be to
abstract the storage type (strbuf versus a long), how to append
(strbuf_addstr vs bitwise OR), how to initialize, which CURLOPT to use,
and so on. But the resulting code looks pretty magical:

  GIT_CURL_PROTOCOL_TYPE allowed = GIT_CURL_PROTOCOL_TYPE_INIT;
  if (...http is allowed...)
GIT_CURL_PROTOCOL_APPEND(&allowed, "http", CURLOPT_HTTP);

and you end up with more "#define GIT_CURL_PROTOCOL_TYPE" macros than
actual code.

On the other end of the spectrum, we could just implement two separate
functions, one that handles a string list and one that handles bits. But
then we end up repeating our list of protocols (http, https, ftp, ftp).

This patch takes the middle ground. The run-time code is always there to
handle both types, and we just choose which one to feed to curl.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agohttp: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
Jeff King [Tue, 17 Jan 2023 03:04:44 +0000 (22:04 -0500)] 
http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION

The IOCTLFUNCTION option has been deprecated, and generates a compiler
warning in recent versions of curl. We can switch to using SEEKFUNCTION
instead. It was added in 2008 via curl 7.18.0; our INSTALL file already
indicates we require at least curl 7.19.4.

But there's one catch: curl says we should use CURL_SEEKFUNC_{OK,FAIL},
and those didn't arrive until 7.19.5. One workaround would be to use a
bare 0/1 here (or define our own macros).  But let's just bump the
minimum required version to 7.19.5. That version is only a minor version
bump from our existing requirement, and is only a 2 month time bump for
versions that are almost 13 years old. So it's not likely that anybody
cares about the distinction.

Switching means we have to rewrite the ioctl functions into seek
functions. In some ways they are simpler (seeking is the only
operation), but in some ways more complex (the ioctl allowed only a full
rewind, but now we can seek to arbitrary offsets).

Curl will only ever use SEEK_SET (per their documentation), so I didn't
bother implementing anything else, since it would naturally be
completely untested. This seems unlikely to change, but I added an
assertion just in case.

Likewise, I doubt curl will ever try to seek outside of the buffer sizes
we've told it, but I erred on the defensive side here, rather than do an
out-of-bounds read.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agohttp-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
Jeff King [Tue, 17 Jan 2023 03:04:38 +0000 (22:04 -0500)] 
http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT

The two options do exactly the same thing, but the latter has been
deprecated and in recent versions of curl may produce a compiler
warning. Since the UPLOAD form is available everywhere (it was
introduced in the year 2000 by curl 7.1), we can just switch to it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agoattr: adjust a mismatched data type
Johannes Schindelin [Thu, 12 Jan 2023 00:05:02 +0000 (01:05 +0100)] 
attr: adjust a mismatched data type

On platforms where `size_t` does not have the same width as `unsigned
long`, passing a pointer to the former when a pointer to the latter is
expected can lead to problems.

Windows and 32-bit Linux are among the affected platforms.

In this instance, we want to store the size of the blob that was read in
that variable. However, `read_blob_data_from_index()` passes that
pointer to `read_object_file()` which expects an `unsigned long *`.
Which means that on affected platforms, the variable is not fully
populated and part of its value is left uninitialized. (On Big-Endian
platforms, this problem would be even worse.)

The consequence is that depending on the uninitialized memory's
contents, we may erroneously reject perfectly fine attributes.

Let's address this by passing a pointer to a variable of the expected
data type.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agofsck: document the new `gitattributes` message IDs
Johannes Schindelin [Thu, 12 Jan 2023 19:43:31 +0000 (20:43 +0100)] 
fsck: document the new `gitattributes` message IDs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agols-tree: remove dead store and strbuf for quote_c_style()
René Scharfe [Sat, 14 Jan 2023 15:03:16 +0000 (16:03 +0100)] 
ls-tree: remove dead store and strbuf for quote_c_style()

Stop initializing "name" because it is set again before use.

Let quote_c_style() write directly to "sb" instead of taking a detour
through "quoted".  This avoids an allocation and a string copy.  The
result is the same because the function only appends.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agols-tree: fix expansion of repeated %(path)
René Scharfe [Sat, 14 Jan 2023 14:37:53 +0000 (15:37 +0100)] 
ls-tree: fix expansion of repeated %(path)

expand_show_tree() borrows the base strbuf given to us by read_tree() to
build the full path of the current entry when handling %(path).  Only
its indirect caller, show_tree_fmt(), removes the added entry name.
That works fine as long as %(path) is only included once in the format
string, but accumulates duplicates if it's repeated:

   $ git ls-tree --format='%(path) %(path) %(path)' HEAD M*
   Makefile MakefileMakefile MakefileMakefileMakefile

Reset the length after each use to get the same expansion every time;
here's the behavior with this patch:

   $ ./git ls-tree --format='%(path) %(path) %(path)' HEAD M*
   Makefile Makefile Makefile

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agogithooks: discuss Git operations in foreign repositories
Eric Sunshine [Mon, 9 Jan 2023 19:45:08 +0000 (19:45 +0000)] 
githooks: discuss Git operations in foreign repositories

Hook authors are periodically caught off-guard by difficult-to-diagnose
errors when their hook invokes Git commands in a repository other than
the local one. In particular, Git environment variables, such as GIT_DIR
and GIT_WORK_TREE, which reference the local repository cause the Git
commands to operate on the local repository rather than on the
repository which the author intended. This is true whether the
environment variables have been set manually by the user or
automatically by Git itself. The same problem crops up when a hook
invokes Git commands in a different worktree of the same repository, as
well.

Recommended best-practice[1,2,3,4,5,6] for avoiding this problem is for
the hook to ensure that Git variables are unset before invoking Git
commands in foreign repositories or other worktrees:

    unset $(git rev-parse --local-env-vars)

However, this advice is not documented anywhere. Rectify this
shortcoming by mentioning it in githooks.txt documentation.

[1]: https://lore.kernel.org/git/YFuHd1MMlJAvtdzb@coredump.intra.peff.net/
[2]: https://lore.kernel.org/git/20200228190218.GC1408759@coredump.intra.peff.net/
[3]: https://lore.kernel.org/git/20190516221702.GA11784@sigill.intra.peff.net/
[4]: https://lore.kernel.org/git/20190422162127.GC9680@sigill.intra.peff.net/
[5]: https://lore.kernel.org/git/20180716183942.GB22298@sigill.intra.peff.net/
[6]: https://lore.kernel.org/git/20150203163235.GA9325@peff.net/

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agogit-rebase.txt: add a note about 'ORIG_HEAD' being overwritten
Philippe Blain [Tue, 10 Jan 2023 13:15:21 +0000 (13:15 +0000)] 
git-rebase.txt: add a note about 'ORIG_HEAD' being overwritten

'ORIG_HEAD' is written at the start of the rebase, but is not guaranteed
to still point to the original branch tip at the end of the rebase.

Indeed, using other commands that write 'ORIG_HEAD' during the rebase,
like splitting a commit using 'git reset HEAD^', will lead to 'ORIG_HEAD'
being overwritten. This causes confusion for some users [1].

Add a note about that in the 'Description' section, and mention the more
robust alternative of using the branch's reflog.

[1] https://lore.kernel.org/git/28ebf03b-e8bb-3769-556b-c9db17e43dbb@gmail.com/T/#m827179c5adcfb504d67f76d03c8e6942b55e5ed0

Reported-by: Erik Cervin Edin <erik@cervined.in>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agorevisions.txt: be explicit about commands writing 'ORIG_HEAD'
Philippe Blain [Tue, 10 Jan 2023 13:15:20 +0000 (13:15 +0000)] 
revisions.txt: be explicit about commands writing 'ORIG_HEAD'

When mentioning 'ORIG_HEAD', be explicit about which command write that
pseudo-ref, namely 'git am', 'git merge', 'git rebase' and 'git reset'.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agogit-merge.txt: mention 'ORIG_HEAD' in the Description
Philippe Blain [Tue, 10 Jan 2023 13:15:19 +0000 (13:15 +0000)] 
git-merge.txt: mention 'ORIG_HEAD' in the Description

The fact that 'git merge' writes 'ORIG_HEAD' before performing the merge
is missing from the documentation of the command.

Mention it in the 'Description' section.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agogit-reset.txt: mention 'ORIG_HEAD' in the Description
Philippe Blain [Tue, 10 Jan 2023 13:15:18 +0000 (13:15 +0000)] 
git-reset.txt: mention 'ORIG_HEAD' in the Description

The fact that 'git reset' writes 'ORIG_HEAD' before changing HEAD is
mentioned in an example, but is missing from the 'Description' section.

Mention it in the discussion of the "'git reset' [<mode>] [<commit>]"
form of the command.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 months agogit-cherry-pick.txt: do not use 'ORIG_HEAD' in example
Philippe Blain [Tue, 10 Jan 2023 13:15:17 +0000 (13:15 +0000)] 
git-cherry-pick.txt: do not use 'ORIG_HEAD' in example

Commit 67ac1e1d57 (cherry-pick/revert: add support for
-X/--strategy-option, 2010-12-10) added an example to the documentation
of 'git cherry-pick'. This example mentions how to abort a failed
cherry-pick and retry with an additional merge strategy option.

The command used in the example to abort the cherry-pick is 'git reset
--merge ORIG_HEAD', but cherry-pick does not write 'ORIG_HEAD' before
starting its operation. So this command would checkout a commit
unrelated to what was at HEAD when the user invoked cherry-pick.

Use 'git cherry-pick --abort' instead.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agouse enhanced basic regular expressions on macOS
René Scharfe [Sun, 8 Jan 2023 00:42:04 +0000 (01:42 +0100)] 
use enhanced basic regular expressions on macOS

When 1819ad327b (grep: fix multibyte regex handling under macOS,
2022-08-26) started to use the native regex library instead of Git's
own (compat/regex/), it lost support for alternation in basic
regular expressions.

Bring it back by enabling the flag REG_ENHANCED on macOS when
compiling basic regular expressions.

Reported-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodiff: drop "name" parameter from prepare_temp_file()
Jeff King [Fri, 6 Jan 2023 11:05:00 +0000 (06:05 -0500)] 
diff: drop "name" parameter from prepare_temp_file()

The prepare_temp_file() function takes a diff_filespec as well as a
filename. But it is almost certainly an error to pass in a name that
isn't the filespec's "path" parameter, since that is the only thing that
reliably tells us how to find the content (and indeed, this was the
source of a recently-fixed bug).

So let's drop the redundant "name" parameter and just use one->path
throughout the function. This simplifies the interface a little bit, and
makes it impossible for calling code to get it wrong.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodiff: clean up external-diff argv setup
Jeff King [Fri, 6 Jan 2023 11:04:18 +0000 (06:04 -0500)] 
diff: clean up external-diff argv setup

Since the previous commit, setting up the tempfile for an external diff
uses df->path from the diff_filespec, rather than the logical name. This
means add_external_diff_name() does not need to take a "name" parameter
at all, and we can drop it. And that in turn lets us simplify the
conditional for handling renames (when the "other" name is non-NULL).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodiff: use filespec path to set up tempfiles for ext-diff
Jeff King [Fri, 6 Jan 2023 11:03:57 +0000 (06:03 -0500)] 
diff: use filespec path to set up tempfiles for ext-diff

When we're going to run an external diff, we have to make the contents
of the pre- and post-images available either by dumping them to a
tempfile, or by pointing at a valid file in the worktree. The logic of
this is all handled by prepare_temp_file(), and we just pass in the
filename and the diff_filespec.

But there's a gotcha here. The "filename" we have is a logical filename
and not necessarily a path on disk or in the repository. This matters in
at least one case: when using "--relative", we may have a name like
"foo", even though the file content is found at "subdir/foo". As a
result, we look for the wrong path, fail to find "foo", and claim that
the file has been deleted (passing "/dev/null" to the external diff,
rather than the correct worktree path).

We can fix this by passing the pathname from the diff_filespec, which
should always be a full repository path (and that's what we want even if
reusing a worktree file, since we're always operating from the top-level
of the working tree).

The breakage seems to go all the way back to cd676a5136 (diff
--relative: output paths as relative to the current subdirectory,
2008-02-12). As far as I can tell, before then "name" would always have
been the same as the filespec's "path".

There are two related cases I looked at that aren't buggy:

  1. the only other caller of prepare_temp_file() is run_textconv(). But
     it always passes the filespec's path field, so it's OK.

  2. I wondered if file renames/copies might cause similar confusion.
     But they don't, because run_external_diff() receives two names in
     that case: "name" and "other", which correspond to the two sides of
     the diff. And we did correctly pass "other" when handling the
     post-image side. Barring the use of "--relative", that would always
     match "two->path", the path of the second filespec (and the rename
     destination).

So the only bug is just the interaction with external diff drivers and
--relative.

Reported-by: Carl Baldwin <carl@ecbaldwin.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agodir: check for single file cone patterns
William Sprent [Tue, 3 Jan 2023 08:20:59 +0000 (08:20 +0000)] 
dir: check for single file cone patterns

The sparse checkout documentation states that the cone mode pattern set
is limited to patterns that either recursively include directories or
patterns that match all files in a directory. In the sparse checkout
file, the former manifest in the form:

    /A/B/C/

while the latter become a pair of patterns either in the form:

    /A/B/
    !/A/B/*/

or in the special case of matching the toplevel files:

    /*
    !/*/

The 'add_pattern_to_hashsets()' function contains checks which serve to
disable cone-mode when non-cone patterns are encountered. However, these
do not catch when the pattern list attempts to match a single file or
directory, e.g. a pattern in the form:

    /A/B/C

This causes sparse-checkout to exhibit unexpected behaviour when such a
pattern is in the sparse-checkout file and cone mode is enabled.
Concretely, with the pattern like the above, sparse-checkout, in
non-cone mode, will only include the directory or file located at
'/A/B/C'. However, with cone mode enabled, sparse-checkout will instead
just manifest the toplevel files but not any file located at '/A/B/C'.

Relatedly, issues occur when supplying the same kind of filter when
partial cloning with '--filter=sparse:oid=<oid>'. 'upload-pack' will
correctly just include the objects that match the non-cone pattern
matching. Which means that checking out the newly cloned repo with the
same filter, but with cone mode enabled, fails due to missing objects.

To fix these issues, add a cone mode pattern check that asserts that
every pattern is either a directory match or the pattern '/*'. Add a
test to verify the new pattern check and modify another to reflect that
non-directory patterns are caught earlier.

Signed-off-by: William Sprent <williams@unity3d.com>
Acked-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobundle <cmd>: have usage_msg_opt() note the missing "<file>"
Ævar Arnfjörð Bjarmason [Tue, 27 Dec 2022 18:39:10 +0000 (19:39 +0100)] 
bundle <cmd>: have usage_msg_opt() note the missing "<file>"

Improve the usage we emit on e.g. "git bundle create" to note why
we're showing the usage, it's because the "<file>" argument is
missing.

We know that'll be the case for all parse_options_cmd_bundle() users,
as they're passing the "char **bundle_file" parameter, which as the
context shows we're expected to populate.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobuiltin/bundle.c: remove superfluous "newargc" variable
Ævar Arnfjörð Bjarmason [Tue, 27 Dec 2022 18:39:09 +0000 (19:39 +0100)] 
builtin/bundle.c: remove superfluous "newargc" variable

As noted in 891cb09db6c (bundle: don't segfault on "git bundle
<subcmd>", 2022-12-20) the "newargc" in this function is redundant to
using our own "argc". Let's refactor the function to avoid needlessly
introducing another variable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agorefs: fix corruption by not correctly syncing packed-refs to disk
Patrick Steinhardt [Tue, 20 Dec 2022 14:52:14 +0000 (15:52 +0100)] 
refs: fix corruption by not correctly syncing packed-refs to disk

At GitLab we have recently received a report where a repository was left
with a corrupted `packed-refs` file after the node hard-crashed even
though `core.fsync=reference` was set. This is something that in theory
should not happen if we correctly did the atomic-rename dance to:

    1. Write the data into a temporary file.

    2. Synchronize the temporary file to disk.

    3. Rename the temporary file into place.

So if we crash in the middle of writing the `packed-refs` file we should
only ever see either the old or the new state of the file.

And while we do the dance when writing the `packed-refs` file, there is
indeed one gotcha: we use a `FILE *` stream to write the temporary file,
but don't flush it before synchronizing it to disk. As a consequence any
data that is still buffered will not get synchronized and a crash of the
machine may cause corruption.

Fix this bug by flushing the file stream before we fsync.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agobundle: don't segfault on "git bundle <subcmd>"
Ævar Arnfjörð Bjarmason [Tue, 20 Dec 2022 13:40:18 +0000 (14:40 +0100)] 
bundle: don't segfault on "git bundle <subcmd>"

Since aef7d75e580 (builtin/bundle.c: let parse-options parse
subcommands, 2022-08-19) we've been segfaulting if no argument was
provided.

The fix is easy, as all of the "git bundle" subcommands require a
non-option argument we can check that we have arguments left after
calling parse-options().

This makes use of code added in 73c3253d75e (bundle: framework for
options before bundle file, 2019-11-10), before this change that code
has always been unreachable. In 73c3253d75e we'd never reach it as we
already checked "argc < 2" in cmd_bundle() itself.

Then when aef7d75e580 (whose segfault we're fixing here) migrated this
code to the subcommand API it removed that "argc < 2" check, but we
were still checking the wrong "argc" in parse_options_cmd_bundle(), we
need to check the "newargc". The "argc" will always be >= 1, as it
will necessarily contain at least the subcommand name
itself (e.g. "create").

As an aside, this could be safely squashed into this, but let's not do
that for this minimal segfault fix, as it's an unrelated refactoring:

--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -55,13 +55,12 @@ static int parse_options_cmd_bundle(int argc,
  const char * const usagestr[],
  const struct option options[],
  char **bundle_file) {
- int newargc;
- newargc = parse_options(argc, argv, NULL, options, usagestr,
+ argc = parse_options(argc, argv, NULL, options, usagestr,
       PARSE_OPT_STOP_AT_NON_OPTION);
- if (!newargc)
+ if (!argc)
  usage_with_options(usagestr, options);
  *bundle_file = prefix_filename(prefix, argv[0]);
- return newargc;
+ return argc;
 }

 static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {

Reported-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Tested-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoci (check-whitespace): move to actions/checkout@v3
Chris. Webster [Tue, 20 Dec 2022 00:35:47 +0000 (00:35 +0000)] 
ci (check-whitespace): move to actions/checkout@v3

Get rid of deprecation warnings in the CI runs.  Also gets the latest
security patches.

Signed-off-by: Chris. Webster <chris@webstech.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 months agoci (check-whitespace): add links to job output
Chris. Webster [Tue, 20 Dec 2022 00:35:46 +0000 (00:35 +0000)] 
ci (check-whitespace): add links to job output

A message in the step log will refer to the Summary output.

The job summary output is using markdown to improve readability.  The
git commands and commits with errors are now in ordered lists.
Commits and files in error are links to the user's repository.

Signed-off-by: Chris. Webster <chris@webstech.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>