Skip to contentSkip to conversation

Prevent a short allocation by checking upper_length

PATCH In review Colin Wee 4 participants 9 messages May 3, 2024 – May 28, 2024

lore
Share & tools
lore

Colin Wee

author
#0 lore raw

PATCH 1/1 Prevent a short allocation by checking upper_length

Hey Connman Maintainers,

I'd like to submit a patch fixing potential memory corruption in connman. I've attached it for review, please let me know what you think.

-Colin

From c9452e34e45be8b54fac0996464f4a5487799377 Mon Sep 17 00:00:00 2001
From: Tesla OpenSource <[email protected]>
Date: Fri, 3 May 2024 14:50:22 -0700
Subject: [PATCH] Prevent a short allocation by checking upper_length

---
 gdhcp/client.c | 2 ++
 1 file changed, 2 insertions(+)
gdhcp/client.c +2 -0
index 2afa19e6..c9234a18 100644
@@ -1863,6 +1863,8 @@ static char *malloc_option_value_string(uint8_t *option, GDHCPOptionType type)
 		return NULL;
 	upper_length = len_of_option_as_string[type] *
 			((unsigned)len / (unsigned)optlen);
+	if (upper_length == 0)
+		return NULL;
 	dest = ret = g_malloc(upper_length + 1);
 	if (!ret)
 		return NULL;
Signature · 1 line
2.45.0
#1 lore raw

Hi Colin,

Quoted 2 lines

I'd like to submit a patch fixing potential memory corruption in connman. I've attached it for review, please let me know what you think.

we prefer inline patches for easier review. Best works a combination git format-patch and then git-send-email.

Can you also please have a human behind the author name and email address since we don’t accept patches from mailing list or aliases.

Regards

Marcel

author
#2 lore raw

Sure thing! I've updated the patch, let me know how else I can help.

-Colin

author
#5 lore raw

PATCH 1/1 Prevent a short allocation by checking upper_length

From: Craig Young <[email protected]>

---
 gdhcp/client.c | 2 ++
 1 file changed, 2 insertions(+)
gdhcp/client.c +2 -0
index 2afa19e6..c9234a18 100644
@@ -1863,6 +1863,8 @@ static char *malloc_option_value_string(uint8_t *option, GDHCPOptionType type)
 		return NULL;
 	upper_length = len_of_option_as_string[type] *
 			((unsigned)len / (unsigned)optlen);
+	if (upper_length == 0)
+		return NULL;
 	dest = ret = g_malloc(upper_length + 1);
 	if (!ret)
 		return NULL;
Signature · 1 line
2.45.0
author
#6 lore raw

Hey Marcel / Connman team,

Just wanted to check in here. Have you had a chance to review this patch?

-Colin

Quoted 21 lines · Colin Wee

From: Craig Young <[email protected]>

---
 gdhcp/client.c | 2 ++
 1 file changed, 2 insertions(+)
gdhcp/client.c +2 -0
index 2afa19e6..c9234a18 100644
@@ -1863,6 +1863,8 @@ static char *malloc_option_value_string(uint8_t *option, GDHCPOptionType type)
 		return NULL;
 	upper_length = len_of_option_as_string[type] *
 			((unsigned)len / (unsigned)optlen);
+	if (upper_length == 0)
+		return NULL;
 	dest = ret = g_malloc(upper_length + 1);
 	if (!ret)
 		return NULL;
Signature · 1 line
2.45.0
#7 lore raw
In reply to Colin Wee

Hi Craig,

Quoted 6 lines · Colin Wee

From: Craig Young <[email protected]>

---
  gdhcp/client.c | 2 ++
  1 file changed, 2 insertions(+)

I added a gdhcp: prefix to the commit subject. Applied, thanks.

If you have other fixes, feel free to send these in.

Regards,
-Denis

#8 lore raw
In reply to Colin Wee
This patch was applied to connman.git (master) by Denis Kenzior <[email protected]>:

Hello:

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

Quoted 5 lines · On Fri, 10 May 2024 23:53:30 +0000 you wrote:

From: Craig Young <[email protected]>

---
 gdhcp/client.c | 2 ++
 1 file changed, 2 insertions(+)

Here is the summary with links:
- Prevent a short allocation by checking upper_length

    https://git.kernel.org/pub/scm/network/connman/connman.git/?id=281e352c4c43

You are awesome, thank you!

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