diff --color-moved-ws: fix double free crash

Running

  git diff --color-moved-ws=allow-indentation-change v2.18.0 v2.19.0

results in a crash due to a double free. This happens when two
potential moved blocks start with consecutive lines. As
pmb_advance_or_null_multi_match() advances it copies the ws_delta from
the last matching line to the next. When the first of our consecutive
lines is advanced its ws_delta well be copied to the second,
overwriting the ws_delta of the block containing the second line. Then
when the second line is advanced it will copy the new ws_delta to the
line below it and so on. Eventually one of these blocks will stop
matching and the ws_delta will be freed. From then on the other block
is in a use-after-free state and when it stops matching it will try to
free the ws_delta that has already been freed by the other block.

The solution is to store the ws_delta in the array of potential moved
blocks rather than with the lines. This means that it no longer needs
to be copied around and one block cannot overwrite the ws_delta of
another. Additionally it saves some malloc/free calls as we don't keep
allocating and freeing ws_deltas.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 64941cf83b6582e066c14ae27d01297d194153c1
  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. perl/
  15. po/
  16. ppc/
  17. refs/
  18. sha1dc/
  19. t/
  20. templates/
  21. vcs-svn/
  22. xdiff/
  23. .clang-format
  24. .gitattributes
  25. .gitignore
  26. .gitmodules
  27. .mailmap
  28. .travis.yml
  29. .tsan-suppressions
  30. abspath.c
  31. aclocal.m4
  32. advice.c
  33. advice.h
  34. alias.c
  35. alias.h
  36. alloc.c
  37. alloc.h
  38. apply.c
  39. apply.h
  40. archive-tar.c
  41. archive-zip.c
  42. archive.c
  43. archive.h
  44. argv-array.c
  45. argv-array.h
  46. attr.c
  47. attr.h
  48. banned.h
  49. base85.c
  50. bisect.c
  51. bisect.h
  52. blame.c
  53. blame.h
  54. blob.c
  55. blob.h
  56. branch.c
  57. branch.h
  58. builtin.h
  59. bulk-checkin.c
  60. bulk-checkin.h
  61. bundle.c
  62. bundle.h
  63. cache-tree.c
  64. cache-tree.h
  65. cache.h
  66. chdir-notify.c
  67. chdir-notify.h
  68. check-builtins.sh
  69. check-racy.c
  70. check_bindir
  71. checkout.c
  72. checkout.h
  73. color.c
  74. color.h
  75. column.c
  76. column.h
  77. combine-diff.c
  78. command-list.txt
  79. commit-graph.c
  80. commit-graph.h
  81. commit-reach.c
  82. commit-reach.h
  83. commit-slab-decl.h
  84. commit-slab-impl.h
  85. commit-slab.h
  86. commit.c
  87. commit.h
  88. common-main.c
  89. config.c
  90. config.h
  91. config.mak.dev
  92. config.mak.in
  93. config.mak.uname
  94. configure.ac
  95. connect.c
  96. connect.h
  97. connected.c
  98. connected.h
  99. convert.c
  100. convert.h
  101. copy.c
  102. COPYING
  103. credential-cache--daemon.c
  104. credential-cache.c
  105. credential-store.c
  106. credential.c
  107. credential.h
  108. csum-file.c
  109. csum-file.h
  110. ctype.c
  111. daemon.c
  112. date.c
  113. decorate.c
  114. decorate.h
  115. delta-islands.c
  116. delta-islands.h
  117. delta.h
  118. detect-compiler
  119. diff-delta.c
  120. diff-lib.c
  121. diff-no-index.c
  122. diff.c
  123. diff.h
  124. diffcore-break.c
  125. diffcore-delta.c
  126. diffcore-order.c
  127. diffcore-pickaxe.c
  128. diffcore-rename.c
  129. diffcore.h
  130. dir-iterator.c
  131. dir-iterator.h
  132. dir.c
  133. dir.h
  134. editor.c
  135. entry.c
  136. environment.c
  137. exec-cmd.c
  138. exec-cmd.h
  139. fast-import.c
  140. fetch-negotiator.c
  141. fetch-negotiator.h
  142. fetch-object.c
  143. fetch-object.h
  144. fetch-pack.c
  145. fetch-pack.h
  146. fmt-merge-msg.h
  147. fsck.c
  148. fsck.h
  149. fsmonitor.c
  150. fsmonitor.h
  151. generate-cmdlist.sh
  152. gettext.c
  153. gettext.h
  154. git-add--interactive.perl
  155. git-archimport.perl
  156. git-bisect.sh
  157. git-compat-util.h
  158. git-cvsexportcommit.perl
  159. git-cvsimport.perl
  160. git-cvsserver.perl
  161. git-difftool--helper.sh
  162. git-filter-branch.sh
  163. git-instaweb.sh
  164. git-merge-octopus.sh
  165. git-merge-one-file.sh
  166. git-merge-resolve.sh
  167. git-mergetool--lib.sh
  168. git-mergetool.sh
  169. git-p4.py
  170. git-parse-remote.sh
  171. git-quiltimport.sh
  172. git-rebase--am.sh
  173. git-rebase--interactive.sh
  174. git-rebase--merge.sh
  175. git-rebase--preserve-merges.sh
  176. git-rebase.sh
  177. git-remote-testgit.sh
  178. git-request-pull.sh
  179. git-send-email.perl
  180. git-sh-i18n.sh
  181. git-sh-setup.sh
  182. git-stash.sh
  183. git-submodule.sh
  184. git-svn.perl
  185. GIT-VERSION-GEN
  186. git-web--browse.sh
  187. git.c
  188. git.rc
  189. gpg-interface.c
  190. gpg-interface.h
  191. graph.c
  192. graph.h
  193. grep.c
  194. grep.h
  195. hash.h
  196. hashmap.c
  197. hashmap.h
  198. help.c
  199. help.h
  200. hex.c
  201. http-backend.c
  202. http-fetch.c
  203. http-push.c
  204. http-walker.c
  205. http.c
  206. http.h
  207. ident.c
  208. imap-send.c
  209. INSTALL
  210. interdiff.c
  211. interdiff.h
  212. iterator.h
  213. json-writer.c
  214. json-writer.h
  215. khash.h
  216. kwset.c
  217. kwset.h
  218. levenshtein.c
  219. levenshtein.h
  220. LGPL-2.1
  221. line-log.c
  222. line-log.h
  223. line-range.c
  224. line-range.h
  225. linear-assignment.c
  226. linear-assignment.h
  227. list-objects-filter-options.c
  228. list-objects-filter-options.h
  229. list-objects-filter.c
  230. list-objects-filter.h
  231. list-objects.c
  232. list-objects.h
  233. list.h
  234. ll-merge.c
  235. ll-merge.h
  236. lockfile.c
  237. lockfile.h
  238. log-tree.c
  239. log-tree.h
  240. ls-refs.c
  241. ls-refs.h
  242. mailinfo.c
  243. mailinfo.h
  244. mailmap.c
  245. mailmap.h
  246. Makefile
  247. match-trees.c
  248. mem-pool.c
  249. mem-pool.h
  250. merge-blobs.c
  251. merge-blobs.h
  252. merge-recursive.c
  253. merge-recursive.h
  254. merge.c
  255. mergesort.c
  256. mergesort.h
  257. midx.c
  258. midx.h
  259. name-hash.c
  260. notes-cache.c
  261. notes-cache.h
  262. notes-merge.c
  263. notes-merge.h
  264. notes-utils.c
  265. notes-utils.h
  266. notes.c
  267. notes.h
  268. object-store.h
  269. object.c
  270. object.h
  271. oidmap.c
  272. oidmap.h
  273. oidset.c
  274. oidset.h
  275. pack-bitmap-write.c
  276. pack-bitmap.c
  277. pack-bitmap.h
  278. pack-check.c
  279. pack-objects.c
  280. pack-objects.h
  281. pack-revindex.c
  282. pack-revindex.h
  283. pack-write.c
  284. pack.h
  285. packfile.c
  286. packfile.h
  287. pager.c
  288. parse-options-cb.c
  289. parse-options.c
  290. parse-options.h
  291. patch-delta.c
  292. patch-ids.c
  293. patch-ids.h
  294. path.c
  295. path.h
  296. pathspec.c
  297. pathspec.h
  298. pkt-line.c
  299. pkt-line.h
  300. preload-index.c
  301. pretty.c
  302. pretty.h
  303. prio-queue.c
  304. prio-queue.h
  305. progress.c
  306. progress.h
  307. prompt.c
  308. prompt.h
  309. protocol.c
  310. protocol.h
  311. quote.c
  312. quote.h
  313. range-diff.c
  314. range-diff.h
  315. reachable.c
  316. reachable.h
  317. read-cache.c
  318. README.md
  319. ref-filter.c
  320. ref-filter.h
  321. reflog-walk.c
  322. reflog-walk.h
  323. refs.c
  324. refs.h
  325. refspec.c
  326. refspec.h
  327. RelNotes
  328. remote-curl.c
  329. remote-testsvn.c
  330. remote.c
  331. remote.h
  332. replace-object.c
  333. replace-object.h
  334. repository.c
  335. repository.h
  336. rerere.c
  337. rerere.h
  338. resolve-undo.c
  339. resolve-undo.h
  340. revision.c
  341. revision.h
  342. run-command.c
  343. run-command.h
  344. send-pack.c
  345. send-pack.h
  346. sequencer.c
  347. sequencer.h
  348. serve.c
  349. serve.h
  350. server-info.c
  351. setup.c
  352. sh-i18n--envsubst.c
  353. sha1-array.c
  354. sha1-array.h
  355. sha1-file.c
  356. sha1-lookup.c
  357. sha1-lookup.h
  358. sha1-name.c
  359. sha1dc_git.c
  360. sha1dc_git.h
  361. shallow.c
  362. shell.c
  363. shortlog.h
  364. sideband.c
  365. sideband.h
  366. sigchain.c
  367. sigchain.h
  368. split-index.c
  369. split-index.h
  370. strbuf.c
  371. strbuf.h
  372. streaming.c
  373. streaming.h
  374. string-list.c
  375. string-list.h
  376. sub-process.c
  377. sub-process.h
  378. submodule-config.c
  379. submodule-config.h
  380. submodule.c
  381. submodule.h
  382. symlinks.c
  383. tag.c
  384. tag.h
  385. tar.h
  386. tempfile.c
  387. tempfile.h
  388. thread-utils.c
  389. thread-utils.h
  390. tmp-objdir.c
  391. tmp-objdir.h
  392. trace.c
  393. trace.h
  394. trailer.c
  395. trailer.h
  396. transport-helper.c
  397. transport-internal.h
  398. transport.c
  399. transport.h
  400. tree-diff.c
  401. tree-walk.c
  402. tree-walk.h
  403. tree.c
  404. tree.h
  405. unicode-width.h
  406. unimplemented.sh
  407. unix-socket.c
  408. unix-socket.h
  409. unpack-trees.c
  410. unpack-trees.h
  411. upload-pack.c
  412. upload-pack.h
  413. url.c
  414. url.h
  415. urlmatch.c
  416. urlmatch.h
  417. usage.c
  418. userdiff.c
  419. userdiff.h
  420. utf8.c
  421. utf8.h
  422. varint.c
  423. varint.h
  424. version.c
  425. version.h
  426. versioncmp.c
  427. walker.c
  428. walker.h
  429. wildmatch.c
  430. wildmatch.h
  431. worktree.c
  432. worktree.h
  433. wrap-for-bin.sh
  434. wrapper.c
  435. write-or-die.c
  436. ws.c
  437. wt-status.c
  438. wt-status.h
  439. xdiff-interface.c
  440. xdiff-interface.h
  441. 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 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-.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 https://public-inbox.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