Skip to contentSkip to conversation

client: Fix possible stack corruption

PATCH Applied Łukasz Rymanowski 2 participants 2 messages May 7, 2020 – May 11, 2020 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 client: Fix possible stack corruption

DBUS_TYPE_BOOLEAN is 'int', which does not have to be the same size as 'bool'.
On architecture where bool is smaller than in, getting prepare-authorize will corrupt the stack

---
 client/gatt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
client/gatt.c +6 -3
index 416eda953..9d35b54fa 100644
@@ -1860,9 +1860,12 @@ static int parse_options(DBusMessageIter *iter, uint16_t *offset, uint16_t *mtu,
 		} else if (strcasecmp(key, "prepare-authorize") == 0) {
 			if (var != DBUS_TYPE_BOOLEAN)
 				return -EINVAL;
-			if (prep_authorize)
-				dbus_message_iter_get_basic(&value,
-								prep_authorize);
+			if (prep_authorize) {
+				int tmp;
+
+				dbus_message_iter_get_basic(&value, &tmp);
+				*prep_authorize = !!tmp;
+			}
 		}
 
 		dbus_message_iter_next(&dict);
Signature · 1 line
2.20.1
Applied
#1 lore raw

Hi Łukasz,

Quoted 13 lines · On Thursday, 7 May 2020 23:45:37 CEST Łukasz Rymanowski wrote:

DBUS_TYPE_BOOLEAN is 'int', which does not have to be the same size as 'bool'.
On architecture where bool is smaller than in, getting prepare-authorize will corrupt the stack

---
 client/gatt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
client/gatt.c +0 -0
index 416eda953..9d35b54fa 100644

client/gatt.c static int parse_options(DBusMessageIter *iter, · line 1866

Quoted 7 lines
client/gatt.c +0 -3
@@ -1860,9 +1860,12 @@ static int parse_options(DBusMessageIter *iter,
 uint16_t *offset, uint16_t *mtu, } else if (strcasecmp(key,
 "prepare-authorize") == 0) {
 			if (var != DBUS_TYPE_BOOLEAN)
 				return -EINVAL;
-			if (prep_authorize)
-				dbus_message_iter_get_basic(&value,
-								

prep_authorize);

client/gatt.c static int parse_options(DBusMessageIter *iter, uint16_t *offset, uint16_t *mtu,

Quoted 4 lines
client/gatt.c +4 -0
+			if (prep_authorize) {
+				int tmp;
+
+				dbus_message_iter_get_basic(&value, 

&tmp);

Quoted 5 lines
client/gatt.c +2 -0
+				*prep_authorize = !!tmp;
+			}
 		}
 

dbus_message_iter_next(&dict);

Applied, thanks.

Signature · 2 lines
pozdrawiam
Szymon Janc