Skip to contentSkip to conversation

uuid-helper: Accept any 16-bit HEX value as a valid UUID

PATCH In review Arkadiusz Bokowy 3 participants 4 messages Mar 2, 2025 – Mar 3, 2025 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 uuid-helper: Accept any 16-bit HEX value as a valid UUID

The bt_name2string() function restricts HEX values to the list of predefined service names. This list is very limited, so loosing that restriction will allow to pass any 16-bit HEX value as a profile to D-Bus API calls like ConnectProfile or RegisterProfile.

---
 src/uuid-helper.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
src/uuid-helper.c +5 -6
index b62b1af82..9d19c5a29 100644
@@ -169,7 +169,8 @@ static int string2uuid16(uuid_t *uuid, const char *string)
 char *bt_name2string(const char *pattern)
 {
 	uuid_t uuid;
-	uint16_t uuid16;
+	unsigned int uuid16;
+	char *endptr = NULL;
 	int i;
 
 	/* UUID 128 string format */
@@ -182,11 +183,9 @@ char *bt_name2string(const char *pattern)
 		goto proceed;
 
 	/* HEX format */
-	uuid16 = strtol(pattern, NULL, 16);
-	for (i = 0; bt_services[i].class; i++) {
-		if (bt_services[i].class == uuid16)
-			goto proceed;
-	}
+	uuid16 = strtoul(pattern, &endptr, 16);
+	if (uuid16 <= 0xffff && *endptr == '\0')
+		goto proceed;
 
 	return NULL;
 
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/2 core: Report error in case of bt_name2string failure

---
 src/device.c  | 4 ++++
 src/profile.c | 2 ++
 2 files changed, 6 insertions(+)
src/device.c +4 -0
index ec97fc889..aca28af8c 100644
@@ -2646,6 +2646,10 @@ static DBusMessage *connect_profile(DBusConnection *conn, DBusMessage *msg,
 	}
 
 	uuid = bt_name2string(pattern);
+	if (uuid == NULL)
+		return btd_error_invalid_args_str(msg,
+					ERR_BREDR_CONN_INVALID_ARGUMENTS);
+
 	reply = connect_profiles(dev, BDADDR_BREDR, msg, uuid);
 	free(uuid);
 
src/profile.c +2 -0
index 9fdfb7dff..ad2043628 100644
@@ -2319,6 +2319,8 @@ static int parse_ext_opt(struct ext_profile *ext, const char *key,
 		dbus_message_iter_get_basic(value, &str);
 		free(ext->service);
 		ext->service = bt_name2string(str);
+		if (ext->service == NULL)
+			return -EINVAL;
 	}
 
 	return 0;
Signature · 1 line
2.39.5
#2 lore raw
In reply to Arkadiusz Bokowy

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=939333

---Test result---

Test Summary:

CheckPatch                    PENDING   0.18 seconds
GitLint                       PENDING   0.23 seconds
BuildEll                      PASS      20.74 seconds
BluezMake                     FAIL      49.22 seconds
MakeCheck                     FAIL      161.90 seconds
MakeDistcheck                 PASS      161.68 seconds
CheckValgrind                 FAIL      41.66 seconds
CheckSmatch                   FAIL      96.07 seconds
bluezmakeextell               FAIL      23.41 seconds
IncrementalBuild              PENDING   0.24 seconds
ScanBuild                     PASS      890.74 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: BluezMake - FAIL
Desc: Build BlueZ
Output:

src/uuid-helper.c: In function ‘bt_name2string’:
src/uuid-helper.c:174:6: error: unused variable ‘i’ [-Werror=unused-variable]
174 | int i;
| ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:7851: src/uuid-helper.o] Error 1
make[1]: *** Waiting for unfinished jobs....
tools/mgmt-tester.c: In function ‘main’:
tools/mgmt-tester.c:12893:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without 12893 | int main(int argc, char *argv[])

      |     ^~~~

make: *** [Makefile:4682: all] Error 2
##############################
Test: MakeCheck - FAIL
Desc: Run Bluez Make Check
Output:

src/uuid-helper.c: In function ‘bt_name2string’:
src/uuid-helper.c:174:6: error: unused variable ‘i’ [-Werror=unused-variable]
174 | int i;
| ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:7851: src/uuid-helper.o] Error 1
make: *** [Makefile:12320: check] Error 2
##############################
Test: CheckValgrind - FAIL
Desc: Run Bluez Make Check with Valgrind
Output:

src/uuid-helper.c: In function ‘bt_name2string’:
src/uuid-helper.c:174:6: error: unused variable ‘i’ [-Werror=unused-variable]
174 | int i;
| ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:7851: src/uuid-helper.o] Error 1
make[1]: *** Waiting for unfinished jobs....
tools/mgmt-tester.c: In function ‘main’:
tools/mgmt-tester.c:12893:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without 12893 | int main(int argc, char *argv[])

      |     ^~~~

make: *** [Makefile:12320: check] Error 2
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

src/shared/crypto.c:271:21: warning: Variable length array is used. src/shared/crypto.c:272:23: warning: Variable length array is used. src/shared/gatt-helpers.c:768:31: warning: Variable length array is used. src/shared/gatt-helpers.c:830:31: warning: Variable length array is used. src/shared/gatt-helpers.c:1323:31: warning: Variable length array is used. src/shared/gatt-helpers.c:1354:23: warning: Variable length array is used. src/shared/gatt-server.c:278:25: warning: Variable length array is used. src/shared/gatt-server.c:618:25: warning: Variable length array is used. src/shared/gatt-server.c:716:25: warning: Variable length array is used. src/shared/bap.c:305:25: warning: array of flexible structures
src/shared/bap.c: note: in included file:
./src/shared/ascs.h:88:25: warning: array of flexible structures
src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):
/usr/include/readline/rltypedefs.h:35:23: warning: non-ANSI function declaration of function 'Function' /usr/include/readline/rltypedefs.h:36:25: warning: non-ANSI function declaration of function 'VFunction' /usr/include/readline/rltypedefs.h:37:27: warning: non-ANSI function declaration of function 'CPFunction' /usr/include/readline/rltypedefs.h:38:29: warning: non-ANSI function declaration of function 'CPPFunction' src/shared/crypto.c:271:21: warning: Variable length array is used. src/shared/crypto.c:272:23: warning: Variable length array is used. src/shared/gatt-helpers.c:768:31: warning: Variable length array is used. src/shared/gatt-helpers.c:830:31: warning: Variable length array is used. src/shared/gatt-helpers.c:1323:31: warning: Variable length array is used. src/shared/gatt-helpers.c:1354:23: warning: Variable length array is used. src/shared/gatt-server.c:278:25: warning: Variable length array is used. src/shared/gatt-server.c:618:25: warning: Variable length array is used. src/shared/gatt-server.c:716:25: warning: Variable length array is used. src/shared/bap.c:305:25: warning: array of flexible structures
src/shared/bap.c: note: in included file:
./src/shared/ascs.h:88:25: warning: array of flexible structures
src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):
/usr/include/readline/rltypedefs.h:35:23: warning: non-ANSI function declaration of function 'Function' /usr/include/readline/rltypedefs.h:36:25: warning: non-ANSI function declaration of function 'VFunction' /usr/include/readline/rltypedefs.h:37:27: warning: non-ANSI function declaration of function 'CPFunction' /usr/include/readline/rltypedefs.h:38:29: warning: non-ANSI function declaration of function 'CPPFunction' tools/mesh-cfgtest.c:1453:17: warning: unknown escape sequence: '\%'
tools/sco-tester.c: note: in included file:
./lib/bluetooth.h:232:15: warning: array of flexible structures
./lib/bluetooth.h:237:31: warning: array of flexible structures
tools/bneptest.c:634:39: warning: unknown escape sequence: '\%'
tools/seq2bseq.c:57:26: warning: Variable length array is used.
src/uuid-helper.c: In function ‘bt_name2string’:
src/uuid-helper.c:174:6: error: unused variable ‘i’ [-Werror=unused-variable]
174 | int i;
| ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:7851: src/uuid-helper.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4682: all] Error 2
##############################
Test: bluezmakeextell - FAIL
Desc: Build Bluez with External ELL
Output:

src/uuid-helper.c: In function ‘bt_name2string’:
src/uuid-helper.c:174:6: error: unused variable ‘i’ [-Werror=unused-variable]
174 | int i;
| ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:7851: src/uuid-helper.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4682: all] Error 2
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Arkadiusz Bokowy
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

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

Quoted 7 lines · On Sun, 2 Mar 2025 10:03:30 +0100 you wrote:

The bt_name2string() function restricts HEX values to the list of predefined service names. This list is very limited, so loosing that restriction will allow to pass any 16-bit HEX value as a profile to D-Bus API calls like ConnectProfile or RegisterProfile.

---
 src/uuid-helper.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Here is the summary with links:
- [BlueZ,1/2] uuid-helper: Accept any 16-bit HEX value as a valid UUID (no matching commit)
- [BlueZ,2/2] core: Report error in case of bt_name2string failure

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

You are awesome, thank you!

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