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

Re: [PATCH] object-info: init request_info before reading arg

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 3, 2023, 16:36 UTC
Message-ID
<xmqqsfdg7wif.fsf@gitster.g>
In-Reply-To
<20230402130557.17662-1-worldhello.net@gmail.com>
Jiang Xin <worldhello.net@gmail.com> writes:
Show 5 quoted lines
> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
>
> When retrieving object info via capability "object-info", we store the
> command args into a requested_info variable, but forget to initialize
> it. Initialize the variable before use to prevent unexpected output.

Good eyes. We read the request packets to decide if we want to flip the .size member of the structure, but the result would not make much sense if the structure starts with a random garbage in it.

I wonder if we can tell our compilers (or runtime checker) to help catch a mistake like this. Did you see our sanitizers complain, or something?

Will queue.  Thanks.
Show 17 quoted lines
> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
> ---
>  protocol-caps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/protocol-caps.c b/protocol-caps.c
> index 874bc815b4..94c51862c5 100644
> --- a/protocol-caps.c
> +++ b/protocol-caps.c
> @@ -79,7 +79,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
>  
>  int cap_object_info(struct repository *r, struct packet_reader *request)
>  {
> -	struct requested_info info;
> +	struct requested_info info = { 0 };
>  	struct packet_writer writer;
>  	struct string_list oid_str_list = STRING_LIST_INIT_DUP;
Previous: Jiang XinNext: Jiang Xin
Message 2 of 3 in “object-info: init request_info before reading arg”
  1. object-info: init request_info before reading argJiang Xin, Apr 2, 2023
  2. Junio C HamanoApr 3, 2023
  3. Jiang XinApr 4, 2023

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.