line-log.c: prevent crash during union of too many ranges

The existing implementation of range_set_union does not correctly
reallocate memory, leading to a heap overflow when it attempts to union
more than 24 separate line ranges.

For struct range_set *out to grow correctly it must have out->nr set to
the current size of the buffer when it is passed to range_set_grow.
However, the existing implementation of range_set_union only updates
out->nr at the end of the function, meaning that it is always zero
before this. This results in range_set_grow never growing the buffer, as
well as some of the union logic itself being incorrect as !out->nr is
always true.

The reason why 24 is the limit is that the first allocation of size 1
ends up allocating a buffer of size 24 (due to the call to alloc_nr in
ALLOC_GROW). This goes some way to explain why this hasn't been
caught before.

Fix the problem by correctly updating out->nr after reallocating the
range_set. As this results in out->nr containing the same value as the
variable o, replace o with out->nr as well.

Finally, add a new test to help prevent the problem reoccurring in the
future. Thanks to Vegard Nossum for writing the test.

Signed-off-by: Allan Xavier <allan.x.xavier@oracle.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: 16d8fb532ed7f5ade4b18711b94a7f75778237a2
  1. block-sha1/
  2. builtin/
  3. ci/
  4. compat/
  5. contrib/
  6. Documentation/
  7. ewah/
  8. git-gui/
  9. gitk-git/
  10. gitweb/
  11. mergetools/
  12. perl/
  13. po/
  14. ppc/
  15. refs/
  16. t/
  17. templates/
  18. vcs-svn/
  19. xdiff/
  20. .gitattributes
  21. .gitignore
  22. .mailmap
  23. .travis.yml
  24. abspath.c
  25. aclocal.m4
  26. advice.c
  27. advice.h
  28. alias.c
  29. alloc.c
  30. archive-tar.c
  31. archive-zip.c
  32. archive.c
  33. archive.h
  34. argv-array.c
  35. argv-array.h
  36. attr.c
  37. attr.h
  38. base85.c
  39. bisect.c
  40. bisect.h
  41. blob.c
  42. blob.h
  43. branch.c
  44. branch.h
  45. builtin.h
  46. bulk-checkin.c
  47. bulk-checkin.h
  48. bundle.c
  49. bundle.h
  50. cache-tree.c
  51. cache-tree.h
  52. cache.h
  53. check-builtins.sh
  54. check-racy.c
  55. check_bindir
  56. color.c
  57. color.h
  58. column.c
  59. column.h
  60. combine-diff.c
  61. command-list.txt
  62. commit-slab.h
  63. commit.c
  64. commit.h
  65. common-main.c
  66. config.c
  67. config.mak.in
  68. config.mak.uname
  69. configure.ac
  70. connect.c
  71. connect.h
  72. connected.c
  73. connected.h
  74. convert.c
  75. convert.h
  76. copy.c
  77. COPYING
  78. credential-cache--daemon.c
  79. credential-cache.c
  80. credential-store.c
  81. credential.c
  82. credential.h
  83. csum-file.c
  84. csum-file.h
  85. ctype.c
  86. daemon.c
  87. date.c
  88. decorate.c
  89. decorate.h
  90. delta.h
  91. diff-delta.c
  92. diff-lib.c
  93. diff-no-index.c
  94. diff.c
  95. diff.h
  96. diffcore-break.c
  97. diffcore-delta.c
  98. diffcore-order.c
  99. diffcore-pickaxe.c
  100. diffcore-rename.c
  101. diffcore.h
  102. dir-iterator.c
  103. dir-iterator.h
  104. dir.c
  105. dir.h
  106. editor.c
  107. entry.c
  108. environment.c
  109. exec_cmd.c
  110. exec_cmd.h
  111. fast-import.c
  112. fetch-pack.c
  113. fetch-pack.h
  114. fmt-merge-msg.h
  115. fsck.c
  116. fsck.h
  117. generate-cmdlist.sh
  118. gettext.c
  119. gettext.h
  120. git-add--interactive.perl
  121. git-archimport.perl
  122. git-bisect.sh
  123. git-compat-util.h
  124. git-cvsexportcommit.perl
  125. git-cvsimport.perl
  126. git-cvsserver.perl
  127. git-difftool--helper.sh
  128. git-difftool.perl
  129. git-filter-branch.sh
  130. git-instaweb.sh
  131. git-merge-octopus.sh
  132. git-merge-one-file.sh
  133. git-merge-resolve.sh
  134. git-mergetool--lib.sh
  135. git-mergetool.sh
  136. git-p4.py
  137. git-parse-remote.sh
  138. git-quiltimport.sh
  139. git-rebase--am.sh
  140. git-rebase--interactive.sh
  141. git-rebase--merge.sh
  142. git-rebase.sh
  143. git-relink.perl
  144. git-remote-testgit.sh
  145. git-request-pull.sh
  146. git-send-email.perl
  147. git-sh-i18n.sh
  148. git-sh-setup.sh
  149. git-stash.sh
  150. git-submodule.sh
  151. git-svn.perl
  152. GIT-VERSION-GEN
  153. git-web--browse.sh
  154. git.c
  155. git.rc
  156. gpg-interface.c
  157. gpg-interface.h
  158. graph.c
  159. graph.h
  160. grep.c
  161. grep.h
  162. hashmap.c
  163. hashmap.h
  164. help.c
  165. help.h
  166. hex.c
  167. http-backend.c
  168. http-fetch.c
  169. http-push.c
  170. http-walker.c
  171. http.c
  172. http.h
  173. ident.c
  174. imap-send.c
  175. INSTALL
  176. iterator.h
  177. khash.h
  178. kwset.c
  179. kwset.h
  180. levenshtein.c
  181. levenshtein.h
  182. LGPL-2.1
  183. line-log.c
  184. line-log.h
  185. line-range.c
  186. line-range.h
  187. list-objects.c
  188. list-objects.h
  189. list.h
  190. ll-merge.c
  191. ll-merge.h
  192. lockfile.c
  193. lockfile.h
  194. log-tree.c
  195. log-tree.h
  196. mailinfo.c
  197. mailinfo.h
  198. mailmap.c
  199. mailmap.h
  200. Makefile
  201. match-trees.c
  202. merge-blobs.c
  203. merge-blobs.h
  204. merge-recursive.c
  205. merge-recursive.h
  206. merge.c
  207. mergesort.c
  208. mergesort.h
  209. mru.c
  210. mru.h
  211. name-hash.c
  212. notes-cache.c
  213. notes-cache.h
  214. notes-merge.c
  215. notes-merge.h
  216. notes-utils.c
  217. notes-utils.h
  218. notes.c
  219. notes.h
  220. object.c
  221. object.h
  222. pack-bitmap-write.c
  223. pack-bitmap.c
  224. pack-bitmap.h
  225. pack-check.c
  226. pack-objects.c
  227. pack-objects.h
  228. pack-revindex.c
  229. pack-revindex.h
  230. pack-write.c
  231. pack.h
  232. pager.c
  233. parse-options-cb.c
  234. parse-options.c
  235. parse-options.h
  236. patch-delta.c
  237. patch-ids.c
  238. patch-ids.h
  239. path.c
  240. pathspec.c
  241. pathspec.h
  242. pkt-line.c
  243. pkt-line.h
  244. preload-index.c
  245. pretty.c
  246. prio-queue.c
  247. prio-queue.h
  248. progress.c
  249. progress.h
  250. prompt.c
  251. prompt.h
  252. quote.c
  253. quote.h
  254. reachable.c
  255. reachable.h
  256. read-cache.c
  257. README.md
  258. ref-filter.c
  259. ref-filter.h
  260. reflog-walk.c
  261. reflog-walk.h
  262. refs.c
  263. refs.h
  264. remote-curl.c
  265. remote-testsvn.c
  266. remote.c
  267. remote.h
  268. replace_object.c
  269. rerere.c
  270. rerere.h
  271. resolve-undo.c
  272. resolve-undo.h
  273. revision.c
  274. revision.h
  275. run-command.c
  276. run-command.h
  277. send-pack.c
  278. send-pack.h
  279. sequencer.c
  280. sequencer.h
  281. server-info.c
  282. setup.c
  283. sh-i18n--envsubst.c
  284. sha1-array.c
  285. sha1-array.h
  286. sha1-lookup.c
  287. sha1-lookup.h
  288. sha1_file.c
  289. sha1_name.c
  290. shallow.c
  291. shell.c
  292. shortlog.h
  293. show-index.c
  294. sideband.c
  295. sideband.h
  296. sigchain.c
  297. sigchain.h
  298. split-index.c
  299. split-index.h
  300. strbuf.c
  301. strbuf.h
  302. streaming.c
  303. streaming.h
  304. string-list.c
  305. string-list.h
  306. submodule-config.c
  307. submodule-config.h
  308. submodule.c
  309. submodule.h
  310. symlinks.c
  311. tag.c
  312. tag.h
  313. tar.h
  314. tempfile.c
  315. tempfile.h
  316. thread-utils.c
  317. thread-utils.h
  318. trace.c
  319. trace.h
  320. trailer.c
  321. trailer.h
  322. transport-helper.c
  323. transport.c
  324. transport.h
  325. tree-diff.c
  326. tree-walk.c
  327. tree-walk.h
  328. tree.c
  329. tree.h
  330. unicode_width.h
  331. unimplemented.sh
  332. unix-socket.c
  333. unix-socket.h
  334. unpack-trees.c
  335. unpack-trees.h
  336. update_unicode.sh
  337. upload-pack.c
  338. url.c
  339. url.h
  340. urlmatch.c
  341. urlmatch.h
  342. usage.c
  343. userdiff.c
  344. userdiff.h
  345. utf8.c
  346. utf8.h
  347. varint.c
  348. varint.h
  349. version.c
  350. version.h
  351. versioncmp.c
  352. walker.c
  353. walker.h
  354. wildmatch.c
  355. wildmatch.h
  356. worktree.c
  357. worktree.h
  358. wrap-for-bin.sh
  359. wrapper.c
  360. write_or_die.c
  361. ws.c
  362. wt-status.c
  363. wt-status.h
  364. xdiff-interface.c
  365. xdiff-interface.h
  366. zlib.c
README.md

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 http://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-.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). To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org. The mailing list archives are available at http://news.gmane.org/gmane.comp.version-control.git/, http://marc.info/?l=git and other archival sites.

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