Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] gatt-server: Fix integer overflow
@ 2026-07-23  8:42 zuohsh
  2026-08-21  3:31 ` [PATCH v2] " zuohsh
  0 siblings, 1 reply; 7+ messages in thread
From: zuohsh @ 2026-07-23  8:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: zuohsh

By using size_t for realloc len and rejecting allocations exceeding
UINT16_MAX , to prevent truncation into the uint16_t field.
---
 src/shared/gatt-server.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c
index 709a8f94b..328755566 100644
--- a/src/shared/gatt-server.c
+++ b/src/shared/gatt-server.c
@@ -1174,12 +1174,12 @@ static bool append_prep_data(struct prep_write_data *prep_data, uint16_t handle,
 					uint16_t length, uint8_t *value)
 {
 	uint8_t *val;
-	uint16_t len;
+	size_t len;
 
 	if (!length)
 		return true;
 
-	len = prep_data->length + length;
+	len = (size_t)prep_data->length + (size_t)length;
 
 	val = realloc(prep_data->value, len);
 	if (!val)
@@ -1188,7 +1188,11 @@ static bool append_prep_data(struct prep_write_data *prep_data, uint16_t handle,
 	memcpy(val + prep_data->length, value, length);
 
 	prep_data->value = val;
-	prep_data->length = len;
+
+	if (len > UINT16_MAX) {
+		return false;
+	}
+	prep_data->length = (uint16_t)len;
 
 	return true;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-21 11:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23  8:42 [PATCH BlueZ] gatt-server: Fix integer overflow zuohsh
2026-08-21  3:31 ` [PATCH v2] " zuohsh
2026-08-21  4:46   ` [v2] " bluez.test.bot
2026-08-21  7:35     ` [PATCH v3] gatt-server: Fix integer overflow and 3 CI VLA wanings zuohsh
2026-08-21  8:42       ` [v3] " bluez.test.bot
2026-08-21 10:40         ` [PATCH v3] " zuohsh
2026-08-21 11:51           ` [v3] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox