git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 10/26] Check for EOF while parsing mails

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 28, 2017, 13:33 UTC
Message-ID
<alpine.DEB.2.20.1704281346480.3480@virtualbox>
In-Reply-To
<20170428112002.tjkcjjdfqenl2aie@sigill.intra.peff.net>
Hi Peff,
On Fri, 28 Apr 2017, Jeff King wrote:
Show 12 quoted lines
> On Fri, Apr 28, 2017 at 12:41:02PM +0200, Johannes Schindelin wrote:
> 
> > But then, I guess I misunderstood what Coverity complained about:
> > maybe the problem was not so much the isspace() call but that EOF is
> > not being handled correctly. We pass it, unchecked, to ungetc().
> > 
> > It appears that I (or Coverity, if you will), missed another instance
> > where we simply passed EOF unchecked to ungetc().
> 
> I think that is also fine according to the standard.
> 
> Do you happen to have the exact error from Coverity?

Wow, that was unnecessarily hard. It is a major hassle to get to any scan other than the latest one.

But I did it. Call me tenatious.
The report says this:
233        do {
   2. negative_return_fn: Function mingw_fgetc(f) returns a negative number.
   3. var_assign: Assigning: signed variable peek = mingw_fgetc.
234                peek = fgetc(f);
   CID 1049734: Negative array index read (NEGATIVE_RETURNS)
   4.  negative_returns: Using variable peek as an index to array sane_ctype.
235        } while (isspace(peek));
236        ungetc(peek, f);

So part of the thing is that we use mingw_fgetc() instead of fgetc(). However, the return value is *still* the one from the "real" fgetc(), even if we intercept what appears to be a Ctrl+C from an interactive console.

> I'm wondering if it is complaining about some aspect of our custom
> isspace() when used with EOF.

That would appear to be the real issue, yes, and I should have double-checked the claim that POSIX isspace() handles EOF properly: we override isspace() with our own version, after all:

	#define isspace(x) sane_istest(x,GIT_SPACE)
where
	#define sane_istest(x,mask) \
		((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
(rewrapped for readability)

As usual, EOF is defined as -1 in Git for Windows' context, meaning that we look at the last entry of the sane_ctype array, which returns 0 for any sane_istest(x,mask) test for x >= 0x80:

        /* Nothing in the 128.. range */

So it would appear that it happens to work, but I doubt that it was intentional.

Having said that, it is really curious why Coverity should get confused by the code and not realize that casting a negative number to (unsigned char) will make it valid as an index for the sane_ctype array.

I double-checked, and there is no override for the isspace() function in what Coverity calls a "model file" (i.e. pseudo code intended to helping Coverity realize where it can stop reporting false positives).

Show 7 quoted lines
> > The next iteration will have it completely reworked: I no longer guard
> > the isspace() behind an `!= EOF` check, but rather handle an early EOF
> > as I think it should be handled. Extra eyes very welcome (this is the
> > fixup!  patch):
> 
> I do think handling EOF explicitly is probably a better strategy anyway,
> as it lets us tell when we have an empty patch.
I agree, I came to the same conclusion independently.

Ciao, Dscho

Previous: Jeff KingNext: Jeff King
Message 28 of 178 in “Address a couple of issues identified by Coverity”
  1. 00/26 Address a couple of issues identified by CoverityJohannes Schindelin, Apr 26, 2017
  2. 01/26 mingw: avoid memory leak when splitting PATHJohannes Schindelin, Apr 26, 2017
  3. 02/26 winansi: avoid use of uninitialized valueJohannes Schindelin, Apr 26, 2017
  4. 03/26 winansi: avoid buffer overrunJohannes Schindelin, Apr 26, 2017
  5. 04/26 add_commit_patch_id(): avoid allocating memory unnecessarilyJohannes Schindelin, Apr 26, 2017
  6. 06/26 get_mail_commit_oid(): avoid resource leakJohannes Schindelin, Apr 26, 2017
  7. Stefan BellerApr 26, 2017
  8. Junio C HamanoApr 27, 2017
  9. Johannes SchindelinApr 28, 2017
  10. Johannes SixtApr 27, 2017
  11. Johannes SchindelinApr 28, 2017
  12. 05/26 git_config_rename_section_in_file(): avoid resource leakJohannes Schindelin, Apr 26, 2017
  13. 08/26 difftool: close file descriptors after readingJohannes Schindelin, Apr 26, 2017
  14. Junio C HamanoApr 27, 2017
  15. Johannes SchindelinApr 28, 2017
  16. 07/26 http-backend: avoid memory leaksJohannes Schindelin, Apr 26, 2017
  17. Junio C HamanoApr 27, 2017
  18. Johannes SchindelinApr 28, 2017
  19. Junio C HamanoMay 1, 2017
  20. Johannes SchindelinMay 1, 2017
  21. 09/26 status: close file descriptor after reading git-rebase-todoJohannes Schindelin, Apr 26, 2017
  22. 10/26 Check for EOF while parsing mailsJohannes Schindelin, Apr 26, 2017
  23. Junio C HamanoApr 27, 2017
  24. Johannes SchindelinApr 28, 2017
  25. Johannes SixtApr 27, 2017
  26. Johannes SchindelinApr 28, 2017
  27. Jeff KingApr 28, 2017
  28. Johannes SchindelinApr 28, 2017
  29. Jeff KingApr 28, 2017
  30. Jeff KingApr 27, 2017
  31. Johannes SchindelinApr 28, 2017
  32. Jeff KingApr 28, 2017
  33. Johannes SchindelinApr 28, 2017
  34. 11/26 cat-file: fix memory leakJohannes Schindelin, Apr 26, 2017
  35. Junio C HamanoApr 27, 2017
  36. Johannes SchindelinApr 28, 2017
  37. 12/26 checkout: fix memory leakJohannes Schindelin, Apr 26, 2017
  38. Junio C HamanoApr 27, 2017
  39. Johannes SchindelinApr 28, 2017
  40. 13/26 split_commit_in_progress(): fix memory leakJohannes Schindelin, Apr 26, 2017
  41. 14/26 setup_bare_git_dir(): fix memory leakJohannes Schindelin, Apr 26, 2017
  42. Stefan BellerApr 26, 2017
  43. Johannes SchindelinApr 27, 2017
  44. Johannes SixtApr 27, 2017
  45. Johannes SchindelinApr 27, 2017
  46. 15/26 setup_discovered_git_dir(): fix memory leakJohannes Schindelin, Apr 26, 2017
  47. 16/26 pack-redundant: plug memory leakJohannes Schindelin, Apr 26, 2017
  48. 17/26 mktree: plug memory leaks reported by CoverityJohannes Schindelin, Apr 26, 2017
  49. 18/26 fast-export: avoid leaking memory in handle_tag()Johannes Schindelin, Apr 26, 2017
  50. Johannes SixtApr 27, 2017
  51. Johannes SchindelinApr 28, 2017
  52. 19/26 receive-pack: plug memory leak in update()Johannes Schindelin, Apr 26, 2017
  53. 20/26 line-log: avoid memory leakJohannes Schindelin, Apr 26, 2017
  54. Johannes SixtApr 27, 2017
  55. Johannes SchindelinApr 28, 2017
  56. 21/26 shallow: avoid memory leakJohannes Schindelin, Apr 26, 2017
  57. 22/26 add_reflog_for_walk: avoid memory leakJohannes Schindelin, Apr 26, 2017
  58. Johannes SixtApr 27, 2017
  59. Johannes SchindelinApr 28, 2017
  60. 23/26 remote: plug memory leak in match_explicit()Johannes Schindelin, Apr 26, 2017
  61. 26/26 submodule_uses_worktrees(): plug memory leakJohannes Schindelin, Apr 26, 2017
  62. 25/26 show_worktree(): plug memory leakJohannes Schindelin, Apr 26, 2017
  63. 24/26 name-rev: avoid leaking memory in the `deref` caseJohannes Schindelin, Apr 26, 2017
  64. Stefan BellerApr 26, 2017
  65. Johannes SchindelinApr 27, 2017
  66. Stefan BellerApr 28, 2017
  67. Automating Coverity, was Re: [PATCH 00/26] Address a couple of issues identified by CoverityJohannes Schindelin, Apr 28, 2017
  68. Lars SchneiderMay 1, 2017
  69. Johannes SchindelinMay 2, 2017
  70. Johannes SchindelinMay 5, 2017
  71. Johannes SchindelinMay 10, 2017
  72. Stefan BellerMay 10, 2017
  73. Johannes SchindelinMay 11, 2017
  74. Johannes SixtApr 27, 2017
  75. Johannes SchindelinApr 28, 2017
  76. 00/25 Address a couple of issues identified by CoverityJohannes Schindelin, Apr 28, 2017
  77. 01/25 mingw: avoid memory leak when splitting PATHJohannes Schindelin, Apr 28, 2017
  78. 02/25 winansi: avoid use of uninitialized valueJohannes Schindelin, Apr 28, 2017
  79. 03/25 winansi: avoid buffer overrunJohannes Schindelin, Apr 28, 2017
  80. 04/25 add_commit_patch_id(): avoid allocating memory unnecessarilyJohannes Schindelin, Apr 28, 2017
  81. 05/25 git_config_rename_section_in_file(): avoid resource leakJohannes Schindelin, Apr 28, 2017
  82. 07/25 difftool: address a couple of resource/memory leaksJohannes Schindelin, Apr 28, 2017
  83. 06/25 get_mail_commit_oid(): avoid resource leakJohannes Schindelin, Apr 28, 2017
  84. 08/25 status: close file descriptor after reading git-rebase-todoJohannes Schindelin, Apr 28, 2017
  85. 09/25 mailinfo & mailsplit: check for EOF while parsingJohannes Schindelin, Apr 28, 2017
  86. Junio C HamanoMay 2, 2017
  87. Johannes SchindelinMay 2, 2017
  88. 10/25 cat-file: fix memory leakJohannes Schindelin, Apr 28, 2017
  89. 11/25 checkout: fix memory leakJohannes Schindelin, Apr 28, 2017
  90. 12/25 split_commit_in_progress(): fix memory leakJohannes Schindelin, Apr 28, 2017
  91. 13/25 setup_bare_git_dir(): help static analysisJohannes Schindelin, Apr 28, 2017
  92. 14/25 setup_discovered_git_dir(): help static analysisJohannes Schindelin, Apr 28, 2017
  93. Junio C HamanoMay 2, 2017
  94. Johannes SchindelinMay 2, 2017
  95. 15/25 pack-redundant: plug memory leakJohannes Schindelin, Apr 28, 2017
  96. 16/25 mktree: plug memory leaks reported by CoverityJohannes Schindelin, Apr 28, 2017
  97. 17/25 fast-export: avoid leaking memory in handle_tag()Johannes Schindelin, Apr 28, 2017
  98. 18/25 receive-pack: plug memory leak in update()Johannes Schindelin, Apr 28, 2017
  99. 19/25 line-log: avoid memory leakJohannes Schindelin, Apr 28, 2017
  100. 20/25 shallow: avoid memory leakJohannes Schindelin, Apr 28, 2017
  101. 22/25 remote: plug memory leak in match_explicit()Johannes Schindelin, Apr 28, 2017
  102. 23/25 name-rev: avoid leaking memory in the `deref` caseJohannes Schindelin, Apr 28, 2017
  103. Junio C HamanoMay 2, 2017
  104. Junio C HamanoMay 2, 2017
  105. Johannes SchindelinMay 2, 2017
  106. Junio C HamanoMay 4, 2017
  107. 24/25 show_worktree(): plug memory leakJohannes Schindelin, Apr 28, 2017
  108. Junio C HamanoMay 2, 2017
  109. 25/25 submodule_uses_worktrees(): plug memory leakJohannes Schindelin, Apr 28, 2017
  110. Junio C HamanoMay 2, 2017
  111. 21/25 add_reflog_for_walk: avoid memory leakJohannes Schindelin, Apr 28, 2017
  112. 00/25 Address a couple of issues identified by CoverityJohannes Schindelin, May 2, 2017
  113. 01/25 mingw: avoid memory leak when splitting PATHJohannes Schindelin, May 2, 2017
  114. René ScharfeMay 3, 2017
  115. Johannes SchindelinMay 4, 2017
  116. 02/25 winansi: avoid use of uninitialized valueJohannes Schindelin, May 2, 2017
  117. René ScharfeMay 3, 2017
  118. Johannes SchindelinMay 4, 2017
  119. 03/25 winansi: avoid buffer overrunJohannes Schindelin, May 2, 2017
  120. 04/25 add_commit_patch_id(): avoid allocating memory unnecessarilyJohannes Schindelin, May 2, 2017
  121. 06/25 get_mail_commit_oid(): avoid resource leakJohannes Schindelin, May 2, 2017
  122. 07/25 difftool: address a couple of resource/memory leaksJohannes Schindelin, May 2, 2017
  123. 05/25 git_config_rename_section_in_file(): avoid resource leakJohannes Schindelin, May 2, 2017
  124. 08/25 status: close file descriptor after reading git-rebase-todoJohannes Schindelin, May 2, 2017
  125. 09/25 mailinfo & mailsplit: check for EOF while parsingJohannes Schindelin, May 2, 2017
  126. 10/25 cat-file: fix memory leakJohannes Schindelin, May 2, 2017
  127. 12/25 split_commit_in_progress(): fix memory leakJohannes Schindelin, May 2, 2017
  128. René ScharfeMay 3, 2017
  129. Johannes SchindelinMay 4, 2017
  130. René ScharfeMay 6, 2017
  131. Johannes SchindelinMay 9, 2017
  132. 11/25 checkout: fix memory leakJohannes Schindelin, May 2, 2017
  133. 16/25 mktree: plug memory leaks reported by CoverityJohannes Schindelin, May 2, 2017
  134. 13/25 setup_bare_git_dir(): help static analysisJohannes Schindelin, May 2, 2017
  135. 15/25 pack-redundant: plug memory leakJohannes Schindelin, May 2, 2017
  136. 17/25 fast-export: avoid leaking memory in handle_tag()Johannes Schindelin, May 2, 2017
  137. 14/25 setup_discovered_git_dir(): plug memory leakJohannes Schindelin, May 2, 2017
  138. Stefan BellerMay 2, 2017
  139. Jeff KingMay 2, 2017
  140. Johannes SchindelinMay 3, 2017
  141. 18/25 receive-pack: plug memory leak in update()Johannes Schindelin, May 2, 2017
  142. 21/25 add_reflog_for_walk: avoid memory leakJohannes Schindelin, May 2, 2017
  143. 22/25 remote: plug memory leak in match_explicit()Johannes Schindelin, May 2, 2017
  144. 20/25 shallow: avoid memory leakJohannes Schindelin, May 2, 2017
  145. 19/25 line-log: avoid memory leakJohannes Schindelin, May 2, 2017
  146. 24/25 show_worktree(): plug memory leakJohannes Schindelin, May 2, 2017
  147. 25/25 submodule_uses_worktrees(): plug memory leakJohannes Schindelin, May 2, 2017
  148. 23/25 name-rev: avoid leaking memory in the `deref` caseJohannes Schindelin, May 2, 2017
  149. 00/25 Address a couple of issues identified by CoverityJohannes Schindelin, May 4, 2017
  150. 04/25 add_commit_patch_id(): avoid allocating memory unnecessarilyJohannes Schindelin, May 4, 2017
  151. 07/25 difftool: address a couple of resource/memory leaksJohannes Schindelin, May 4, 2017
  152. 06/25 get_mail_commit_oid(): avoid resource leakJohannes Schindelin, May 4, 2017
  153. 05/25 git_config_rename_section_in_file(): avoid resource leakJohannes Schindelin, May 4, 2017
  154. 09/25 mailinfo & mailsplit: check for EOF while parsingJohannes Schindelin, May 4, 2017
  155. 08/25 status: close file descriptor after reading git-rebase-todoJohannes Schindelin, May 4, 2017
  156. 02/25 winansi: avoid use of uninitialized valueJohannes Schindelin, May 4, 2017
  157. 01/25 mingw: avoid memory leak when splitting PATHJohannes Schindelin, May 4, 2017
  158. 03/25 winansi: avoid buffer overrunJohannes Schindelin, May 4, 2017
  159. 10/25 cat-file: fix memory leakJohannes Schindelin, May 4, 2017
  160. 11/25 checkout: fix memory leakJohannes Schindelin, May 4, 2017
  161. René ScharfeMay 6, 2017
  162. Junio C HamanoMay 8, 2017
  163. Johannes SchindelinMay 9, 2017
  164. Junio C HamanoMay 9, 2017
  165. 18/25 receive-pack: plug memory leak in update()Johannes Schindelin, May 4, 2017
  166. 19/25 line-log: avoid memory leakJohannes Schindelin, May 4, 2017
  167. 20/25 shallow: avoid memory leakJohannes Schindelin, May 4, 2017
  168. 12/25 split_commit_in_progress(): simplify & fix memory leakJohannes Schindelin, May 4, 2017
  169. 14/25 setup_discovered_git_dir(): plug memory leakJohannes Schindelin, May 4, 2017
  170. 17/25 fast-export: avoid leaking memory in handle_tag()Johannes Schindelin, May 4, 2017
  171. 16/25 mktree: plug memory leaks reported by CoverityJohannes Schindelin, May 4, 2017
  172. 13/25 setup_bare_git_dir(): help static analysisJohannes Schindelin, May 4, 2017
  173. 21/25 add_reflog_for_walk: avoid memory leakJohannes Schindelin, May 4, 2017
  174. 22/25 remote: plug memory leak in match_explicit()Johannes Schindelin, May 4, 2017
  175. 24/25 show_worktree(): plug memory leakJohannes Schindelin, May 4, 2017
  176. 23/25 name-rev: avoid leaking memory in the `deref` caseJohannes Schindelin, May 4, 2017
  177. 25/25 submodule_uses_worktrees(): plug memory leakJohannes Schindelin, May 4, 2017
  178. 15/25 pack-redundant: plug memory leakJohannes Schindelin, May 4, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.