parse-options: detect mismatches in integer signedness

commit 791aeddfa2fdb9e830e24c50c97bb5e8bf3613e6 upstream.

It was reported that "t5620-backfill.sh" fails on s390x and sparc64 in a
test that exercises the "--min-batch-size" command line option. The
symptom was that the option didn't seem to have an effect: we didn't
fetch objects with a batch size of 20, but instead fetched all objects
at once.

As it turns out, the root cause is that `--min-batch-size` uses
`OPT_INTEGER()` to parse the command line option. While this macro
expects the caller to pass a pointer to an integer, we instead pass a
pointer to a `size_t`. This coincidentally works on most platforms, but
it breaks apart on the mentioned platforms because they are big endian.

This issue isn't specific to git-backfill(1): there are a couple of
other places where we have the same type confusion going on. This
indicates that the issue really is the interface that the parse-options
subsystem provides -- it is simply too easy to get this wrong as there
isn't any kind of compiler warning, and things just work on the most
common systems.

Address the systemic issue by introducing two new build asserts
`BARF_UNLESS_SIGNED()` and `BARF_UNLESS_UNSIGNED()`. As the names
already hint at, those macros will cause a compiler error when passed a
value that is not signed or unsigned, respectively.

Adapt `OPT_INTEGER()`, `OPT_UNSIGNED()` as well as `OPT_MAGNITUDE()` to
use those asserts. This uncovers a small set of sites where we indeed
have the same bug as in git-backfill(1). Adapt all of them to use the
correct option.

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