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

Re: [PATCH] setup: avoid uninitialized use of is_safe in ensure_valid_ownership

From
Carlo Arenas <carenas@gmail.com>
Date
Apr 27, 2022, 09:16 UTC
Message-ID
<CAPUEspgf_PpjjrGaAqeE50fWYeCqevQRGutocNOA4gyYzQzFsA@mail.gmail.com>
In-Reply-To
<CA+zfrf_mHfDXk-1VhU564YeCTW7rgDeeuORdTT61LkTESmC5Og@mail.gmail.com>
On Wed, Apr 27, 2022 at 1:33 AM Matheus Valadares <me@m28.io> wrote:
>
> C99 standard §6.7.8 (Initialization)/21,
>
> If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or 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.

Thanks, I will include the change to remove the path initializer and add instead the is_safe one as part of my bigger change, but FWIW the following doesn't even trigger a warning with the highest level we have with neither a recent clang or gcc or even the cppcheck static analyzer, but leave and uses is_safe uninitialized.

diff --git a/setup.c b/setup.c
index 17c7f5fc1dc..28d008145fa 100644
--- a/setup.c
+++ b/setup.c
@@ -1122,7 +1122,9 @@ static int safe_directory_cb(const char *key,
const char *value, void *d)

 static int ensure_valid_ownership(const char *path)
 {
-       struct safe_directory_data data = { .path = path, .is_safe = 0 };
+       struct safe_directory_data data;
+
+       data.path = path;

        if (!git_env_bool("GIT_TEST_ASSUME_DIFFERENT_OWNER", 0) &&
            is_path_owned_by_current_user(path))

Carlo
Previous: Carlo ArenasNext: Derrick Stolee
Message 4 of 5 in “setup: avoid uninitialized use of is_safe in ensure_valid_ownership”
  1. setup: avoid uninitialized use of is_safe in ensure_valid_ownershipCarlo Marcelo Arenas Belón, Apr 27, 2022
  2. Junio C HamanoApr 27, 2022
  3. Carlo ArenasApr 27, 2022
  4. Carlo ArenasApr 27, 2022
  5. Derrick StoleeApr 27, 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.