Skip to contentSkip to conversation

dhcp6: Fix uninitialized variable build warning

PATCH Applied Mat Martineau 2 participants 2 messages Aug 20, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dhcp6: Fix uninitialized variable build warning

Commit 17f79c855e61 added a variable 'r' to dhcp6_client_rx_message() that holds either a new dhcp6_state or an error (negative value). 'r' was not set in several client states, but it appears that the unit tests only cover cases where it is set.

It appears that the new code at the end of dhcp6_client_rx_message() is only intended for the cases where 'r' was set, so initialize 'r' to the current client->state and rely on the existing state check to preserve old behavior.
---

Denis, I don't have enough background knowledge about DHCPv6 to be 100% sure this patch does the right thing. Is my guess correct about the intended use of the new code at the end of dhcp6_client_rx_message()?

 ell/dhcp6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ell/dhcp6.c +1 -1
index d41cdde..b0c6438 100644
@@ -1148,7 +1148,7 @@ static void dhcp6_client_rx_message(const void *data, size_t len,
 {
 	struct l_dhcp6_client *client = userdata;
 	const struct dhcp6_message *message = data;
-	int r;
+	int r = client->state;
 
 	CLIENT_DEBUG("");
 
Signature · 1 line
2.28.0
#1 lore raw

Hi Mat,

Quoted 9 lines · Mat Martineau

Commit 17f79c855e61 added a variable 'r' to dhcp6_client_rx_message() that holds either a new dhcp6_state or an error (negative value). 'r' was not set in several client states, but it appears that the unit tests only cover cases where it is set.

It appears that the new code at the end of dhcp6_client_rx_message() is only intended for the cases where 'r' was set, so initialize 'r' to the current client->state and rely on the existing state check to preserve old behavior.

Ah thanks for this. I still have some pending changes that masked it on my end.
I need to be more careful.

Quoted 5 lines

---

Denis, I don't have enough background knowledge about DHCPv6 to be 100% sure this patch does the right thing. Is my guess correct about the intended use of the new code at the end of dhcp6_client_rx_message()?

The fix is fine for now. I think eventually all cases will be handled such that r is always set, but I'm not there yet.

Quoted 4 lines

  ell/dhcp6.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis