{"thread":{"id":"59523","subject":"[PATCH] object-info: init request_info before reading arg","startedAt":"2023-04-02T13:06:13Z","lastAt":"2023-04-04T01:08:00Z","messageCount":3,"participants":["Jiang Xin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"474659","messageId":"20230402130557.17662-1-worldhello.net@gmail.com","threadId":"59523","inReplyTo":null,"subject":"[PATCH] object-info: init request_info before reading arg","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2023-04-02T13:05:57Z","receivedAt":"2023-04-02T13:06:13Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"From: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n\nWhen retrieving object info via capability \"object-info\", we store the\ncommand args into a requested_info variable, but forget to initialize\nit. Initialize the variable before use to prevent unexpected output.\n\nSigned-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n---\n protocol-caps.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/protocol-caps.c b/protocol-caps.c\nindex 874bc815b4..94c51862c5 100644\n--- a/protocol-caps.c\n+++ b/protocol-caps.c\n@@ -79,7 +79,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,\n \n int cap_object_info(struct repository *r, struct packet_reader *request)\n {\n-\tstruct requested_info info;\n+\tstruct requested_info info = { 0 };\n \tstruct packet_writer writer;\n \tstruct string_list oid_str_list = STRING_LIST_INIT_DUP;\n \n-- \n2.39.1.418.g7876265d61\n\n"},{"id":"474689","messageId":"xmqqsfdg7wif.fsf@gitster.g","threadId":"59523","inReplyTo":"20230402130557.17662-1-worldhello.net@gmail.com","subject":"Re: [PATCH] object-info: init request_info before reading arg","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-03T16:36:56Z","receivedAt":"2023-04-03T16:37:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jiang Xin <worldhello.net@gmail.com> writes:\n\n> From: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n>\n> When retrieving object info via capability \"object-info\", we store the\n> command args into a requested_info variable, but forget to initialize\n> it. Initialize the variable before use to prevent unexpected output.\n\nGood eyes.  We read the request packets to decide if we want to flip\nthe .size member of the structure, but the result would not make\nmuch sense if the structure starts with a random garbage in it.\n\nI wonder if we can tell our compilers (or runtime checker) to help\ncatch a mistake like this.  Did you see our sanitizers complain, or\nsomething?\n\nWill queue.  Thanks.\n\n> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n> ---\n>  protocol-caps.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/protocol-caps.c b/protocol-caps.c\n> index 874bc815b4..94c51862c5 100644\n> --- a/protocol-caps.c\n> +++ b/protocol-caps.c\n> @@ -79,7 +79,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,\n>  \n>  int cap_object_info(struct repository *r, struct packet_reader *request)\n>  {\n> -\tstruct requested_info info;\n> +\tstruct requested_info info = { 0 };\n>  \tstruct packet_writer writer;\n>  \tstruct string_list oid_str_list = STRING_LIST_INIT_DUP;\n"},{"id":"474734","messageId":"CANYiYbHB9AMpahiULEF=PoVG6y_ogDvVQvWY=ThKUdERmVbQyg@mail.gmail.com","threadId":"59523","inReplyTo":"xmqqsfdg7wif.fsf@gitster.g","subject":"Re: [PATCH] object-info: init request_info before reading arg","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2023-04-04T01:07:43Z","receivedAt":"2023-04-04T01:08:00Z","isPatch":true,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"On Tue, Apr 4, 2023 at 12:36 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Jiang Xin <worldhello.net@gmail.com> writes:\n>\n> > From: Jiang Xin <zhiyou.jx@alibaba-inc.com>\n> >\n> > When retrieving object info via capability \"object-info\", we store the\n> > command args into a requested_info variable, but forget to initialize\n> > it. Initialize the variable before use to prevent unexpected output.\n>\n> Good eyes.  We read the request packets to decide if we want to flip\n> the .size member of the structure, but the result would not make\n> much sense if the structure starts with a random garbage in it.\n>\n> I wonder if we can tell our compilers (or runtime checker) to help\n> catch a mistake like this.  Did you see our sanitizers complain, or\n> something?\n\nI accidentally came across this issue when I wanted to implement a new\nsimilar capability. I'm curious why adding \"-Wuninitialized\" or\n\"-Wmaybe-uninitialized\" to gcc fails to spot this case.\n"}]}