Skip to contentSkip to conversation

properties_changed: check for NULL iterator

PATCH Applied Christian Eggers 3 participants 13 messages Sep 23, 2022 Bluetooth drivers

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover properties_changed: check for NULL iterator

The org.freedesktop.DBus.Properties.PropertiesChanged signal allows sending "invalidated_properties" (only property names without values). In this case the property_changed callbacks are called with NULL iterator by gdbus/client.c::properties_changed():

...
proxy->prop_func(..., ..., iter=NULL, ...)
...

Christian Eggers (9):
advertising: parse_secondary: fix loop condition
advertising: parse_secondary: fix mask value
advertising: parse_secondary: check for NULL iterator
advertising: parse_min_interval: reset min_interval if iter is NULL
advertising: parse_[min|max]_interval: reset value if iter is NULL
advertising: parse_tx_power: reset value if iter is NULL client/gatt: proxy_property_changed: check for NULL iterator
gatt: proxy_property_changed: check for NULL iterator
battery: provided_battery_property_changed_cb: check for NULL iterator

 client/gatt.c       |  5 +++++
 src/advertising.c   | 22 +++++++++++++++++-----
 src/battery.c       | 10 ++++++----
 src/gatt-database.c | 20 +++++++++++---------
 4 files changed, 39 insertions(+), 18 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/9 advertising: parse_secondary: fix loop condition

"secondary" isn't an array of pointers, so the iterator can never be NULL.

---
 src/advertising.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/advertising.c +1 -1
index 1fe371a9f345..15ef44def031 100644
@@ -1055,7 +1055,7 @@ static bool parse_secondary(DBusMessageIter *iter,
 
 	dbus_message_iter_get_basic(iter, &str);
 
-	for (sec = secondary; sec && sec->name; sec++) {
+	for (sec = secondary; sec->name; sec++) {
 		if (strcmp(str, sec->name))
 			continue;
 
Signature · 1 line
2.35.3
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=679824

---Test result---

Test Summary:

CheckPatch                    PASS      12.59 seconds
GitLint                       FAIL      8.83 seconds
Prep - Setup ELL              PASS      26.35 seconds
Build - Prep                  PASS      0.79 seconds
Build - Configure             PASS      8.36 seconds
Build - Make                  PASS      747.77 seconds
Make Check                    PASS      11.00 seconds
Make Check w/Valgrind         PASS      289.46 seconds
Make Distcheck                PASS      239.58 seconds
Build w/ext ELL - Configure   PASS      8.42 seconds
Build w/ext ELL - Make        PASS      84.11 seconds
Incremental Build w/ patches  PASS      892.46 seconds
Scan Build                    WARNING   493.39 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint with rule in .gitlint
Output:
[BlueZ,9/9] battery: provided_battery_property_changed_cb: check for NULL iterator
1: T1 Title exceeds max length (82>80): "[BlueZ,9/9] battery: provided_battery_property_changed_cb: check for NULL iterator"

##############################
Test: Scan Build - WARNING
Desc: Run Scan Build with patches
Output:
*****************************************************************************
The bugs reported by the scan-build may or may not be caused by your patches. Please check the list and fix the bugs if they are caused by your patch.
*****************************************************************************
client/gatt.c:2146:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull'

        memcpy(*dst_value + offset, src_val, src_len);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning generated.

---
Regards,
Linux Bluetooth

#3 lore raw

PATCH 2/9 advertising: parse_secondary: fix mask value

In reply to Christian Eggers

It looks like a wrong mask value is used here as only the bits mentioned in adv_secondary::flag can be set again within the loop.

Replace magic number by preprocessor macro.

---
 src/advertising.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/advertising.c +1 -1
index 15ef44def031..42ac627604fe 100644
@@ -1051,7 +1051,7 @@ static bool parse_secondary(DBusMessageIter *iter,
 		return false;
 
 	/* Reset secondary channels before parsing */
-	client->flags &= 0xfe00;
+	client->flags &= ~MGMT_ADV_FLAG_SEC_MASK;
 
 	dbus_message_iter_get_basic(iter, &str);
 
Signature · 1 line
2.35.3
#4 lore raw

PATCH 3/9 advertising: parse_secondary: check for NULL iterator

In reply to Christian Eggers

The passed iterator can be NULL as in
gdbus/client.c::properties_changed():
...
proxy->prop_func(..., ..., iter=NULL, ...)

   +--src/advertising.c::properties_changed(..., ..., iter, ...);
      +--parse_secondary(iter, ...);
...
---
 src/advertising.c | 6 ++++++
 1 file changed, 6 insertions(+)
src/advertising.c +6 -0
index 42ac627604fe..6d8d06edd34f 100644
@@ -1047,6 +1047,12 @@ static bool parse_secondary(DBusMessageIter *iter,
 	const char *str;
 	struct adv_secondary *sec;
 
+	if (!iter) {
+		/* Reset secondary channels */
+		client->flags &= ~MGMT_ADV_FLAG_SEC_MASK;
+		return true;
+	}
+
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
 		return false;
 
Signature · 1 line
2.35.3
#5 lore raw

PATCH 4/9 advertising: parse_min_interval: reset min_interval if iter is NULL

In reply to Christian Eggers

Set property to its default value (as done in all other methods listed in parsers[]).

---
 src/advertising.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/advertising.c +3 -1
index 6d8d06edd34f..fbfd90b4e300 100644
@@ -1087,8 +1087,10 @@ static bool parse_min_interval(DBusMessageIter *iter,
 	if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL))
 		return true;
 
-	if (!iter)
+	if (!iter) {
+		client->min_interval = 0;
 		return false;
+	}
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32)
 		return false;
Signature · 1 line
2.35.3
#6 lore raw

PATCH 4/9 advertising: parse_min_interval: reset min_interval if iter is NULL

In reply to Christian Eggers

Set property to its default value (as done in all other methods listed in parsers[]).

---
 src/advertising.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/advertising.c +3 -1
index 6d8d06edd34f..fbfd90b4e300 100644
@@ -1087,8 +1087,10 @@ static bool parse_min_interval(DBusMessageIter *iter,
 	if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL))
 		return true;
 
-	if (!iter)
+	if (!iter) {
+		client->min_interval = 0;
 		return false;
+	}
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32)
 		return false;
Signature · 1 line
2.35.3
#7 lore raw

Re: [PATCH BlueZ 4/9] advertising: parse_min_interval: reset min_interval if iter is NULL

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 5 lines · On Fri, 23 Sep 2022 12:26:00 +0200 you wrote:

Set property to its default value (as done in all other methods listed in parsers[]).

---
 src/advertising.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Here is the summary with links:
- [BlueZ,4/9] advertising: parse_min_interval: reset min_interval if iter is NULL

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=abfb3a807c39

You are awesome, thank you!

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

PATCH 5/9 advertising: parse_[min|max]_interval: reset value if iter is NULL

In reply to Christian Eggers

Set property to its default value (as done in all other methods listed in parsers[]).

---
 src/advertising.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/advertising.c +3 -1
index fbfd90b4e300..25df2297b3c1 100644
@@ -1120,8 +1120,10 @@ static bool parse_max_interval(DBusMessageIter *iter,
 	if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL))
 		return true;
 
-	if (!iter)
+	if (!iter) {
+		client->max_interval = 0;
 		return false;
+	}
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32)
 		return false;
Signature · 1 line
2.35.3
#9 lore raw

PATCH 6/9 advertising: parse_tx_power: reset value if iter is NULL

In reply to Christian Eggers

Set property to its default value (as done in all other methods listed in parsers[]).

---
 src/advertising.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/advertising.c +3 -1
index 25df2297b3c1..f9748b1328bc 100644
@@ -1153,8 +1153,10 @@ static bool parse_tx_power(DBusMessageIter *iter,
 	if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL))
 		return true;
 
-	if (!iter)
+	if (!iter) {
+		client->tx_power = ADV_TX_POWER_NO_PREFERENCE;
 		return false;
+	}
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INT16)
 		return false;
Signature · 1 line
2.35.3
#10 lore raw

PATCH 7/9 client/gatt: proxy_property_changed: check for NULL iterator

In reply to Christian Eggers

The passed iterator can be NULL as in
gdbus/client.c::properties_changed():
...
proxy->prop_func(..., ..., iter=NULL, ...)

   +--client/gatt.c::proxy_property_changed(..., ..., iter, ...);
      +--dbus_message_iter_get_arg_type(iter);
...
---
 client/gatt.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
client/gatt.c +10 -7
index efd736b2359a..c3bdd4710897 100644
@@ -3003,17 +3003,20 @@ static void proxy_property_changed(GDBusProxy *proxy, const char *name,
 			chrc->path, bt_uuidstr_to_str(chrc->uuid), name);
 
 	if (!strcmp(name, "Value")) {
-		DBusMessageIter array;
-		uint8_t *value;
-		int len;
+		uint8_t *value = NULL;
+		int len = 0;
+
+		if (iter && dbus_message_iter_get_arg_type(iter) ==
+				DBUS_TYPE_ARRAY) {
+			DBusMessageIter array;
 
-		if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_ARRAY) {
 			dbus_message_iter_recurse(iter, &array);
 			dbus_message_iter_get_fixed_array(&array, &value, &len);
-			write_value(&chrc->value_len, &chrc->value, value, len,
-					0, chrc->max_val_len);
-			bt_shell_hexdump(value, len);
 		}
+
+		write_value(&chrc->value_len, &chrc->value, value, len,
+				0, chrc->max_val_len);
+		bt_shell_hexdump(value, len);
 	}
 
 	g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE, name);
Signature · 1 line
2.35.3
#11 lore raw

PATCH 8/9 gatt: proxy_property_changed: check for NULL iterator

In reply to Christian Eggers

The passed iterator can be NULL as in
src/gatt-database.c::properties_changed():
...
proxy->prop_func(..., ..., iter=NULL, ...)

   +--client/gatt.c::property_changed_cb(..., ..., iter, ...);
      +--dbus_message_iter_get_arg_type(iter);
...
---
 src/gatt-database.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
src/gatt-database.c +11 -9
index c72f4a4d5c54..ea282d4bc193 100644
@@ -2867,17 +2867,19 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
 	if (strcmp(name, "Value"))
 		return;
 
-	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) {
-		DBG("Malformed \"Value\" property received");
-		return;
-	}
+	if (iter) {
+		if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) {
+			DBG("Malformed \"Value\" property received");
+			return;
+		}
 
-	dbus_message_iter_recurse(iter, &array);
-	dbus_message_iter_get_fixed_array(&array, &value, &len);
+		dbus_message_iter_recurse(iter, &array);
+		dbus_message_iter_get_fixed_array(&array, &value, &len);
 
-	if (len < 0) {
-		DBG("Malformed \"Value\" property received");
-		return;
+		if (len < 0) {
+			DBG("Malformed \"Value\" property received");
+			return;
+		}
 	}
 
 	/* Truncate the value if it's too large */
Signature · 1 line
2.35.3
#12 lore raw

PATCH 9/9 battery: provided_battery_property_changed_cb: check for NULL iterator

In reply to Christian Eggers

The passed iterator can be NULL as in
gdbus/client.c::properties_changed():
...
proxy->prop_func(..., ..., iter=NULL, ...)

   +--src/battery.c::provided_battery_property_changed_cb(, , iter, );
      +--dbus_message_iter_get_arg_type(iter);
...
---
 src/battery.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
src/battery.c +6 -4
index 77fee22b6e61..88a53e80e890 100644
@@ -252,7 +252,7 @@ static void provided_battery_property_changed_cb(GDBusProxy *proxy,
 						 DBusMessageIter *iter,
 						 void *user_data)
 {
-	uint8_t percentage;
+	uint8_t percentage = 0;
 	const char *export_path;
 	DBusMessageIter dev_iter;
 
@@ -264,10 +264,12 @@ static void provided_battery_property_changed_cb(GDBusProxy *proxy,
 	if (strcmp(name, "Percentage") != 0)
 		return;
 
-	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BYTE)
-		return;
+	if (iter) {
+		if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BYTE)
+			return;
 
-	dbus_message_iter_get_basic(iter, &percentage);
+		dbus_message_iter_get_basic(iter, &percentage);
+	}
 
 	DBG("battery percentage changed on %s, percentage = %d",
 	    g_dbus_proxy_get_path(proxy), percentage);
Signature · 1 line
2.35.3