contrib/credential: embiggen fixed-size buffer in wincred

As in previous commits, harden the wincred credential helper against the
aforementioned protocol injection attack.

Unlike the approached used for osxkeychain and libsecret, where a
fixed-size buffer was replaced with `getline()`, we must take a
different approach here. There is no `getline()` equivalent in Windows,
and the function is not available to us with ordinary compiler settings.

Instead, allocate a larger (still fixed-size) buffer in which to process
each line. The value of 100 KiB is chosen to match the maximum-length
header that curl will allow, CURL_MAX_HTTP_HEADER.

To ensure that we are reading complete lines at a time, and that we
aren't susceptible to a similar injection attack (albeit with more
padding), ensure that each read terminates at a newline (i.e., that no
line is more than 100 KiB long).

Note that it isn't sufficient to turn the old loop into something like:

    while (len && strchr("\r\n", buf[len - 1])) {
      buf[--len] = 0;
      ends_in_newline = 1;
    }

because if an attacker sends something like:

    [aaaaa.....]\r
    host=example.com\r\n

the credential helper would fill its buffer after reading up through the
first '\r', call fgets() again, and then see "host=example.com\r\n" on
its line.

Note that the original code was written in a way that would trim an
arbitrary number of "\r" and "\n" from the end of the string. We should
get only a single "\n" (since the point of `fgets()` is to return the
buffer to us when it sees one), and likewise would not expect to see
more than one associated "\r". The new code trims a single "\r\n", which
matches the original intent.

[1]: https://curl.se/libcurl/c/CURLOPT_HEADERFUNCTION.html

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