OSDN Git Service

bt: fix sdp service name by removing NULL char
authorTimm Korte <timm.korte@gmail.com>
Mon, 15 May 2017 06:30:00 +0000 (08:30 +0200)
committerAndre Eisenbach <eisenbach@google.com>
Thu, 13 Jul 2017 18:39:47 +0000 (18:39 +0000)
The Bluedroid stack uses a C string with terminating NULL char as a
service name. Since in BT, strings are TLV encoded (type, length,
value), this doesn't make sense.

Simple fix is to copy the string without the trailing NULL by
removing the "+1" after the strlen call when passing the string as
uint8_t array to the lower level functions.
The current behaviour keeps some older devices from being able to
connect to an Android providing a Serial Port profile due to having
the wrong service name (that is, including a NULL at the end instead
of the correct string).

Test: Checked against Linux BlueZ, which does not include this extra
null character.

Bug: 63665003
Change-Id: I6a43024ff89ac09e4b2d2e5cfb407b6e9323f0bd
Signed-off-by: Timm Korte <timm.korte@gmail.com>
(cherry picked from commit 625f798c696229b0cc58e5f85409fd029f987473)

btif/src/btif_sock_sdp.cc

index 21b2c0b..afbfab4 100644 (file)
@@ -127,7 +127,7 @@ static bool create_base_record(const uint32_t sdp_handle, const char* name,
   if (name[0] != '\0') {
     stage = "service_name";
     if (!SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
-                          (uint32_t)(strlen(name) + 1), (uint8_t*)name))
+                          (uint32_t)strlen(name), (uint8_t*)name))
       goto error;
   }