avoid segfault when reading header of malformed commits

If a commit object has a header line at the end of the
buffer that is missing its newline (or if it appears so
because the content on the header line contains a stray
NUL), then git will segfault.

Interestingly, this case is explicitly handled and we do
correctly scan the final line for the header we are looking
for. But if we don't find it, we will dereference NULL while
trying to look at the next line.

Git will never generate such a commit, but it's good to be
defensive. We could die() in such a case, but since it's
easy enough to handle it gracefully, let's just issue a
warning and continue (so you could still view such a commit
with "git show", though you might be missing headers after
the NUL).

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