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

Re: [PATCH 01/11] mingw: avoid accessing uninitialized memory in `is_executable()`

From
René Scharfe <l.s.r@web.de>
Date
Jun 16, 2022, 19:53 UTC
Message-ID
<98ff788a-d621-cf3f-aed5-66ae763b381f@web.de>
In-Reply-To
<679ea7421f73ce41515aca549982233f88bcefef.1655336146.git.gitgitgadget@gmail.com>
Am 16.06.22 um 01:35 schrieb Johannes Schindelin via GitGitGadget:
Show 6 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> On Windows, we open files we suspect might be scripts, read the first
> two bytes, and see whether they indicate a hash-bang line. We do not
> initialize the byte _after_ those two bytes, therefore `strcmp()` is
> inappropriate here.
Hmm, but buf _is_ initialized fully?  Line 149:
        char buf[3] = { 0 };

C99 §6.7.8 21: "If there are [...] fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration."

Show 21 quoted lines
>
> Reported by Coverity.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  run-command.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/run-command.c b/run-command.c
> index 14f17830f51..2ba38850b4d 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -154,7 +154,7 @@ int is_executable(const char *name)
>  		n = read(fd, buf, 2);
>  		if (n == 2)
>  			/* look for a she-bang */
> -			if (!strcmp(buf, "#!"))
> +			if (!memcmp(buf, "#!", 2))
>  				st.st_mode |= S_IXUSR;
>  		close(fd);
>  	}
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 38 in “Coverity fixes”
  1. 00/11 Coverity fixesJohannes Schindelin via GitGitGadget, Jun 15, 2022
  2. 01/11 mingw: avoid accessing uninitialized memory in `is_executable()`Johannes Schindelin via GitGitGadget, Jun 15, 2022
  3. Junio C HamanoJun 16, 2022
  4. René ScharfeJun 16, 2022
  5. Junio C HamanoJun 16, 2022
  6. Junio C HamanoJun 16, 2022
  7. 02/11 fsmonitor: avoid memory leak in `fsm_settings__get_incompatible_msg()`Johannes Schindelin via GitGitGadget, Jun 15, 2022
  8. Junio C HamanoJun 16, 2022
  9. 03/11 submodule--helper: avoid memory leak in `update_submodule()`Johannes Schindelin via GitGitGadget, Jun 15, 2022
  10. Junio C HamanoJun 16, 2022
  11. Glen ChooJun 16, 2022
  12. 04/11 get_oid_with_context_1(): avoid use-after-freeJohannes Schindelin via GitGitGadget, Jun 15, 2022
  13. Junio C HamanoJun 16, 2022
  14. 05/11 submodule-config: avoid memory leakJohannes Schindelin via GitGitGadget, Jun 15, 2022
  15. Junio C HamanoJun 16, 2022
  16. Glen ChooJun 16, 2022
  17. 06/11 pack-redundant: avoid using uninitialized memoryJohannes Schindelin via GitGitGadget, Jun 15, 2022
  18. Junio C HamanoJun 16, 2022
  19. 07/11 submodule--helper: avoid memory leak when fetching submodulesJohannes Schindelin via GitGitGadget, Jun 15, 2022
  20. Junio C HamanoJun 16, 2022
  21. 08/11 read_index_from(): avoid memory leakJohannes Schindelin via GitGitGadget, Jun 15, 2022
  22. 08/11 read_index_from(): avoid memory leakTom Levy, Jun 17, 2022
  23. 09/11 pack-mtimes: avoid closing a bogus file descriptorJohannes Schindelin via GitGitGadget, Jun 15, 2022
  24. Taylor BlauJun 16, 2022
  25. 10/11 relative_url(): fix incorrect conditionJohannes Schindelin via GitGitGadget, Jun 15, 2022
  26. Junio C HamanoJun 16, 2022
  27. Ævar Arnfjörð BjarmasonJun 16, 2022
  28. Junio C HamanoJun 16, 2022
  29. Junio C HamanoJun 16, 2022
  30. 11/11 bug_fl(): add missing `va_end()` callJohannes Schindelin via GitGitGadget, Jun 15, 2022
  31. Jeff KingJun 16, 2022
  32. Junio C HamanoJun 16, 2022
  33. Ævar Arnfjörð BjarmasonJun 16, 2022
  34. Junio C HamanoJun 16, 2022
  35. Jeff KingJun 16, 2022
  36. bug_fl(): correctly initialize trace2 va_listJeff King, Jun 16, 2022
  37. Junio C HamanoJun 16, 2022
  38. Junio C HamanoJun 16, 2022

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.