Skip to contentSkip to conversation

selftests: nci: Fix uninitialized family ID on missing attribute

PATCH In review Chaithanya Lagisetty 2 participants 2 messages Sep 1

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: nci: Fix uninitialized family ID on missing attribute

get_family_id() walks the generic netlink CTRL_CMD_GETFAMILY reply looking for the CTRL_ATTR_FAMILY_ID attribute and returns the parsed value in the local variable "id". If the reply does not carry that attribute, the parsing loop never assigns "id" and the function returns an indeterminate stack value, which the caller stores in self->fid and uses for subsequent netlink requests.

Initialize "id" to 0 so a missing attribute yields a deterministic (invalid) family ID instead of a garbage value.

Fixes f595cf1242f3 ("selftests: Add nci suite")
---
 tools/testing/selftests/nci/nci_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/nci/nci_dev.c +1 -1
index 312f84ee0444..ed306ec23895 100644
@@ -182,7 +182,7 @@ static int get_family_id(int sd, __u32 pid, __u32 *event_group)
 	} ans;
 	struct nlattr *na;
 	int resp_len;
-	__u16 id;
+	__u16 id = 0;
 	int len;
 	int rc;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Chaithanya Lagisetty

get_family_id() walks the generic netlink CTRL_CMD_GETFAMILY reply looking for the CTRL_ATTR_FAMILY_ID attribute and returns the parsed value in the local variable "id". If the reply does not carry that attribute, the parsing loop never assigns "id" and the function returns an indeterminate stack value, which the caller stores in self->fid and uses for subsequent netlink requests.

Initialize "id" to 0 so a missing attribute yields a deterministic (invalid) family ID instead of a garbage value.

Fixes f595cf1242f3 ("selftests: Add nci suite")
---
 tools/testing/selftests/nci/nci_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/nci/nci_dev.c +1 -1
index 312f84ee0444..ed306ec23895 100644
@@ -182,7 +182,7 @@ static int get_family_id(int sd, __u32 pid, __u32 *event_group)
 	} ans;
 	struct nlattr *na;
 	int resp_len;
-	__u16 id;
+	__u16 id = 0;
 	int len;
 	int rc;
 
Signature · 1 line
2.43.0