[PATCH] gdhcp: nul-terminate return for 0 sized option value

[email protected]
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
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(-)

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;
 
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.