Skip to contentSkip to conversation

gdhcp: nul-terminate return for 0 sized option value

PATCH Applied [email protected] 2 participants 2 messages Aug 19, 2024 – Sep 2, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdhcp: nul-terminate return for 0 sized option value

From: Jonah Petri <[email protected]>

In the field I have seen some dhcp servers return a code 252 response with a zero length. In this case, this code has len=0 < optlen=1, in which case the returned string never gets terminated. Using g_malloc0 causes it to always get zero-terminated.

---
 gdhcp/client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gdhcp/client.c +1 -1
index c9234a18..db8e0596 100644
@@ -1865,7 +1865,7 @@ static char *malloc_option_value_string(uint8_t *option, GDHCPOptionType type)
 			((unsigned)len / (unsigned)optlen);
 	if (upper_length == 0)
 		return NULL;
-	dest = ret = g_malloc(upper_length + 1);
+	dest = ret = g_malloc0(upper_length + 1);
 	if (!ret)
 		return NULL;
 
Signature · 1 line
2.34.1
#1 lore raw
This patch was applied to connman.git (master) by Marcel Holtmann <[email protected]>:

Hello:

This patch was applied to connman.git (master)
by Marcel Holtmann <[email protected]>:

Quoted 8 lines · On Mon, 19 Aug 2024 17:14:54 -0400 you wrote:

From: Jonah Petri <[email protected]>

In the field I have seen some dhcp servers return a code 252 response with a zero length. In this case, this code has len=0 < optlen=1, in which case the returned string never gets terminated. Using g_malloc0 causes it to always get zero-terminated.

[...]

Here is the summary with links:
- gdhcp: nul-terminate return for 0 sized option value

    https://git.kernel.org/pub/scm/network/connman/connman.git/?id=8018165a2172

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html