remote-curl: fall back to default hash outside repo

When a remote helper like git-remote-http is invoked outside of a
repository (for example, by running git ls-remote in a non-git
directory), setup_git_directory_gently() leaves the_hash_algo
uninitialized as NULL.

If the user has a globally configured fetch refspec, remote-curl
attempts to parse it during initialization. Inside parse_refspec(),
it checks whether the LHS of the refspec is an exact OID by evaluating
llen == the_hash_algo->hexsz. Because the_hash_algo is NULL, this
results in a segmentation fault.

In 9e89dcb66a (builtin/ls-remote: fall back to SHA1 outside of a repo,
2024-08-02), we added a workaround to ls-remote to fall back to the
default hash algorithm to prevent exactly this type of crash when
parsing refspec capabilities. However, because remote-curl runs as a
separate process, it does not inherit that fallback and crashes anyway.

Instead of pushing a NULL-guard workaround down into parse_refspec(),
fix this by mirroring the ls-remote workaround directly in
remote-curl.c. If we are operating outside a repository, initialize
the_hash_algo to GIT_HASH_DEFAULT. This keeps the HTTP transport
consistent with non-HTTP transports that execute in-process, preventing
crashes without altering the generic refspec parsing logic.

Reported-by: Jo Liss <joliss@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: d173d27e2f507118e0123761f647fb785e9e88f4
  1. .github/
  2. bin-wrappers/
  3. block-sha1/
  4. builtin/
  5. ci/
  6. compat/
  7. compiler-tricks/
  8. contrib/
  9. Documentation/
  10. ewah/
  11. git-gui/
  12. gitk-git/
  13. gitweb/
  14. mergetools/
  15. negotiator/
  16. odb/
  17. oss-fuzz/
  18. perl/
  19. po/
  20. refs/
  21. reftable/
  22. sha1/
  23. sha1dc/
  24. sha256/
  25. src/
  26. subprojects/
  27. t/
  28. templates/
  29. trace2/
  30. xdiff/
  31. .cirrus.yml
  32. .clang-format
  33. .editorconfig
  34. .gitattributes
  35. .gitignore
  36. .gitlab-ci.yml
  37. .gitmodules
  38. .mailmap
  39. .tsan-suppressions
  40. abspath.c
  41. abspath.h
  42. aclocal.m4
  43. add-interactive.c
  44. add-interactive.h
  45. add-patch.c
  46. advice.c
  47. advice.h
  48. alias.c
  49. alias.h
  50. alloc.c
  51. alloc.h
  52. apply.c
  53. apply.h
  54. archive-tar.c
  55. archive-zip.c
  56. archive.c
  57. archive.h
  58. attr.c
  59. attr.h
  60. banned.h
  61. base85.c
  62. base85.h
  63. bisect.c
  64. bisect.h
  65. blame.c
  66. blame.h
  67. blob.c
  68. blob.h
  69. bloom.c
  70. bloom.h
  71. branch.c
  72. branch.h
  73. builtin.h
  74. bundle-uri.c
  75. bundle-uri.h
  76. bundle.c
  77. bundle.h
  78. cache-tree.c
  79. cache-tree.h
  80. Cargo.toml
  81. cbtree.c
  82. cbtree.h
  83. chdir-notify.c
  84. chdir-notify.h
  85. check-builtins.sh
  86. checkout.c
  87. checkout.h
  88. chunk-format.c
  89. chunk-format.h
  90. CODE_OF_CONDUCT.md
  91. color.c
  92. color.h
  93. column.c
  94. column.h
  95. combine-diff.c
  96. command-list.txt
  97. commit-graph.c
  98. commit-graph.h
  99. commit-reach.c
  100. commit-reach.h
  101. commit-slab-decl.h
  102. commit-slab-impl.h
  103. commit-slab.h
  104. commit.c
  105. commit.h
  106. common-exit.c
  107. common-init.c
  108. common-init.h
  109. common-main.c
  110. config.c
  111. config.h
  112. config.mak.dev
  113. config.mak.in
  114. config.mak.uname
  115. configure.ac
  116. connect.c
  117. connect.h
  118. connected.c
  119. connected.h
  120. convert.c
  121. convert.h
  122. copy.c
  123. copy.h
  124. COPYING
  125. credential.c
  126. credential.h
  127. csum-file.c
  128. csum-file.h
  129. ctype.c
  130. daemon.c
  131. date.c
  132. date.h
  133. decorate.c
  134. decorate.h
  135. delta-islands.c
  136. delta-islands.h
  137. delta.h
  138. detect-compiler
  139. diagnose.c
  140. diagnose.h
  141. diff-delta.c
  142. diff-lib.c
  143. diff-merges.c
  144. diff-merges.h
  145. diff-no-index.c
  146. diff.c
  147. diff.h
  148. diffcore-break.c
  149. diffcore-delta.c
  150. diffcore-order.c
  151. diffcore-pickaxe.c
  152. diffcore-rename.c
  153. diffcore-rotate.c
  154. diffcore.h
  155. dir-iterator.c
  156. dir-iterator.h
  157. dir.c
  158. dir.h
  159. editor.c
  160. editor.h
  161. entry.c
  162. entry.h
  163. environment.c
  164. environment.h
  165. exec-cmd.c
  166. exec-cmd.h
  167. fetch-negotiator.c
  168. fetch-negotiator.h
  169. fetch-pack.c
  170. fetch-pack.h
  171. fmt-merge-msg.c
  172. fmt-merge-msg.h
  173. for-each-ref.h
  174. fsck.c
  175. fsck.h
  176. fsmonitor--daemon.h
  177. fsmonitor-ipc.c
  178. fsmonitor-ipc.h
  179. fsmonitor-ll.h
  180. fsmonitor-path-utils.h
  181. fsmonitor-settings.c
  182. fsmonitor-settings.h
  183. fsmonitor.c
  184. fsmonitor.h
  185. generate-cmdlist.sh
  186. generate-configlist.sh
  187. generate-hooklist.sh
  188. generate-perl.sh
  189. generate-python.sh
  190. generate-script.sh
  191. gettext.c
  192. gettext.h
  193. git-archimport.perl
  194. GIT-BUILD-OPTIONS.in
  195. git-compat-util.h
  196. git-curl-compat.h
  197. git-cvsexportcommit.perl
  198. git-cvsimport.perl
  199. git-cvsserver.perl
  200. git-difftool--helper.sh
  201. git-filter-branch.sh
  202. git-instaweb.sh
  203. git-merge-octopus.sh
  204. git-merge-one-file.sh
  205. git-merge-resolve.sh
  206. git-mergetool--lib.sh
  207. git-mergetool.sh
  208. git-p4.py
  209. git-quiltimport.sh
  210. git-request-pull.sh
  211. git-send-email.perl
  212. git-sh-i18n.sh
  213. git-sh-setup.sh
  214. git-submodule.sh
  215. git-svn.perl
  216. GIT-VERSION-FILE.in
  217. GIT-VERSION-GEN
  218. git-web--browse.sh
  219. git-zlib.c
  220. git-zlib.h
  221. git.c
  222. git.rc.in
  223. gpg-interface.c
  224. gpg-interface.h
  225. graph.c
  226. graph.h
  227. grep.c
  228. grep.h
  229. hash-lookup.c
  230. hash-lookup.h
  231. hash.c
  232. hash.h
  233. hashmap.c
  234. hashmap.h
  235. help.c
  236. help.h
  237. hex-ll.c
  238. hex-ll.h
  239. hex.c
  240. hex.h
  241. hook.c
  242. hook.h
  243. http-backend.c
  244. http-fetch.c
  245. http-push.c
  246. http-walker.c
  247. http.c
  248. http.h
  249. ident.c
  250. ident.h
  251. imap-send.c
  252. INSTALL
  253. iterator.h
  254. json-writer.c
  255. json-writer.h
  256. khash.h
  257. kwset.c
  258. kwset.h
  259. levenshtein.c
  260. levenshtein.h
  261. LGPL-2.1
  262. line-log.c
  263. line-log.h
  264. line-range.c
  265. line-range.h
  266. linear-assignment.c
  267. linear-assignment.h
  268. list-objects-filter-options.c
  269. list-objects-filter-options.h
  270. list-objects-filter.c
  271. list-objects-filter.h
  272. list-objects.c
  273. list-objects.h
  274. list.h
  275. lockfile.c
  276. lockfile.h
  277. log-tree.c
  278. log-tree.h
  279. loose.c
  280. loose.h
  281. ls-refs.c
  282. ls-refs.h
  283. mailinfo.c
  284. mailinfo.h
  285. mailmap.c
  286. mailmap.h
  287. Makefile
  288. match-trees.c
  289. match-trees.h
  290. mem-pool.c
  291. mem-pool.h
  292. merge-blobs.c
  293. merge-blobs.h
  294. merge-ll.c
  295. merge-ll.h
  296. merge-ort-wrappers.c
  297. merge-ort-wrappers.h
  298. merge-ort.c
  299. merge-ort.h
  300. merge.c
  301. merge.h
  302. mergesort.h
  303. meson.build
  304. meson_options.txt
  305. midx-write.c
  306. midx.c
  307. midx.h
  308. name-hash.c
  309. name-hash.h
  310. notes-cache.c
  311. notes-cache.h
  312. notes-merge.c
  313. notes-merge.h
  314. notes-utils.c
  315. notes-utils.h
  316. notes.c
  317. notes.h
  318. object-file-convert.c
  319. object-file-convert.h
  320. object-file.c
  321. object-file.h
  322. object-name.c
  323. object-name.h
  324. object.c
  325. object.h
  326. odb.c
  327. odb.h
  328. oid-array.c
  329. oid-array.h
  330. oidmap.c
  331. oidmap.h
  332. oidset.c
  333. oidset.h
  334. oidtree.c
  335. oidtree.h
  336. pack-bitmap-write.c
  337. pack-bitmap.c
  338. pack-bitmap.h
  339. pack-check.c
  340. pack-mtimes.c
  341. pack-mtimes.h
  342. pack-objects.c
  343. pack-objects.h
  344. pack-refs.c
  345. pack-refs.h
  346. pack-revindex.c
  347. pack-revindex.h
  348. pack-write.c
  349. pack.h
  350. packfile.c
  351. packfile.h
  352. pager.c
  353. pager.h
  354. parallel-checkout.c
  355. parallel-checkout.h
  356. parse-options-cb.c
  357. parse-options.c
  358. parse-options.h
  359. parse.c
  360. parse.h
  361. patch-delta.c
  362. patch-ids.c
  363. patch-ids.h
  364. path-walk.c
  365. path-walk.h
  366. path.c
  367. path.h
  368. pathspec.c
  369. pathspec.h
  370. pkt-line.c
  371. pkt-line.h
  372. preload-index.c
  373. preload-index.h
  374. pretty.c
  375. pretty.h
  376. prio-queue.c
  377. prio-queue.h
  378. progress.c
  379. progress.h
  380. promisor-remote.c
  381. promisor-remote.h
  382. prompt.c
  383. prompt.h
  384. protocol-caps.c
  385. protocol-caps.h
  386. protocol.c
  387. protocol.h
  388. prune-packed.c
  389. prune-packed.h
  390. pseudo-merge.c
  391. pseudo-merge.h
  392. quote.c
  393. quote.h
  394. range-diff.c
  395. range-diff.h
  396. reachable.c
  397. reachable.h
  398. read-cache-ll.h
  399. read-cache.c
  400. read-cache.h
  401. README.md
  402. rebase-interactive.c
  403. rebase-interactive.h
  404. rebase.c
  405. rebase.h
  406. ref-filter.c
  407. ref-filter.h
  408. reflog-walk.c
  409. reflog-walk.h
  410. reflog.c
  411. reflog.h
  412. refs.c
  413. refs.h
  414. refspec.c
  415. refspec.h
  416. remote-curl.c
  417. remote.c
  418. remote.h
  419. repack-cruft.c
  420. repack-filtered.c
  421. repack-geometry.c
  422. repack-midx.c
  423. repack-promisor.c
  424. repack.c
  425. repack.h
  426. replace-object.c
  427. replace-object.h
  428. repo-settings.c
  429. repo-settings.h
  430. repository.c
  431. repository.h
  432. rerere.c
  433. rerere.h
  434. reset.c
  435. reset.h
  436. resolve-undo.c
  437. resolve-undo.h
  438. revision.c
  439. revision.h
  440. run-command.c
  441. run-command.h
  442. sane-ctype.h
  443. scalar.c
  444. SECURITY.md
  445. send-pack.c
  446. send-pack.h
  447. sequencer.c
  448. sequencer.h
  449. serve.c
  450. serve.h
  451. server-info.c
  452. server-info.h
  453. setup.c
  454. setup.h
  455. sh-i18n--envsubst.c
  456. sha1dc_git.c
  457. sha1dc_git.h
  458. shallow.c
  459. shallow.h
  460. shared.mak
  461. shell.c
  462. shortlog.h
  463. sideband.c
  464. sideband.h
  465. sigchain.c
  466. sigchain.h
  467. simple-ipc.h
  468. sparse-index.c
  469. sparse-index.h
  470. split-index.c
  471. split-index.h
  472. stable-qsort.c
  473. statinfo.c
  474. statinfo.h
  475. strbuf.c
  476. strbuf.h
  477. string-list.c
  478. string-list.h
  479. strmap.c
  480. strmap.h
  481. strvec.c
  482. strvec.h
  483. sub-process.c
  484. sub-process.h
  485. submodule-config.c
  486. submodule-config.h
  487. submodule.c
  488. submodule.h
  489. symlinks.c
  490. symlinks.h
  491. tag.c
  492. tag.h
  493. tar.h
  494. tempfile.c
  495. tempfile.h
  496. thread-utils.c
  497. thread-utils.h
  498. tmp-objdir.c
  499. tmp-objdir.h
  500. trace.c
  501. trace.h
  502. trace2.c
  503. trace2.h
  504. trailer.c
  505. trailer.h
  506. transport-helper.c
  507. transport-internal.h
  508. transport.c
  509. transport.h
  510. tree-diff.c
  511. tree-walk.c
  512. tree-walk.h
  513. tree.c
  514. tree.h
  515. unicode-width.h
  516. unimplemented.sh
  517. unix-socket.c
  518. unix-socket.h
  519. unix-stream-server.c
  520. unix-stream-server.h
  521. unpack-trees.c
  522. unpack-trees.h
  523. upload-pack.c
  524. upload-pack.h
  525. url.c
  526. url.h
  527. urlmatch.c
  528. urlmatch.h
  529. usage.c
  530. userdiff.c
  531. userdiff.h
  532. utf8.c
  533. utf8.h
  534. varint.c
  535. varint.h
  536. version-def.h.in
  537. version.c
  538. version.h
  539. versioncmp.c
  540. versioncmp.h
  541. walker.c
  542. walker.h
  543. wildmatch.c
  544. wildmatch.h
  545. worktree.c
  546. worktree.h
  547. wrapper.c
  548. wrapper.h
  549. write-or-die.c
  550. write-or-die.h
  551. ws.c
  552. ws.h
  553. wt-status.c
  554. wt-status.h
  555. xdiff-interface.c
  556. xdiff-interface.h
README.md

Build status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.adoc to get started, then see Documentation/giteveryday.adoc for a useful minimum set of commands, and Documentation/git-<commandname>.adoc for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.adoc (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission and Documentation/CodingGuidelines).

Those wishing to help with error message, usage and informational message string translations (localization l10) should see po/README.md (a po file is a Portable Object file that holds the translations).

To subscribe to the list, send an email to git+subscribe@vger.kernel.org (see https://subspace.kernel.org/subscribing.html for details). The mailing list archives are available at https://lore.kernel.org/git/, https://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks