diff mbox series

gdhcp: nul-terminate return for 0 sized option value

Message ID 20240819211454.1255654-1-jonah@petri.us (mailing list archive)
State Accepted
Commit 8018165a217274cbb055feb5812e723e68c6de66
Headers show
Series gdhcp: nul-terminate return for 0 sized option value | expand

Commit Message

jonah@petri.us Aug. 19, 2024, 9:14 p.m. UTC
From: Jonah Petri <jonah@petri.us>

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(-)

Comments

patchwork-bot+connman@kernel.org Sept. 2, 2024, 8:30 a.m. UTC | #1
Hello:

This patch was applied to connman.git (master)
by Marcel Holtmann <marcel@holtmann.org>:

On Mon, 19 Aug 2024 17:14:54 -0400 you wrote:
> From: Jonah Petri <jonah@petri.us>
> 
> 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!
diff mbox series

Patch

diff --git a/gdhcp/client.c b/gdhcp/client.c
index c9234a18..db8e0596 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -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;