Skip to contentSkip to conversation

object-info: init request_info before reading arg

PATCH In review Jiang Xin 2 participants 3 messages Apr 2, 2023 – Apr 4, 2023

lore
Share & tools
lore

Jiang Xin

author
#0 lore raw

PATCH 1/1 object-info: init request_info before reading arg

From: Jiang Xin <[email protected]>

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.

---
 protocol-caps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
protocol-caps.c +1 -1
index 874bc815b4..94c51862c5 100644
@@ -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;
 
Signature · 1 line
2.39.1.418.g7876265d61
#1 lore raw
Quoted 5 lines · Jiang Xin

From: Jiang Xin <[email protected]>

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.

Quoted 17 lines
---
 protocol-caps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
protocol-caps.c +1 -1
index 874bc815b4..94c51862c5 100644
@@ -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;
author
#2 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Jiang Xin

From: Jiang Xin <[email protected]>

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.

Quoted 7 lines

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?

I accidentally came across this issue when I wanted to implement a new similar capability. I'm curious why adding "-Wuninitialized" or "-Wmaybe-uninitialized" to gcc fails to spot this case.