From: Santiago Carot-Nemesio <sancane@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Santiago Carot-Nemesio <sancane@gmail.com>
Subject: [PATCH 8/8] gatt-example: Fix g_assert checks when an uint16_t value overflows
Date: Wed, 25 Jan 2012 14:12:41 +0100 [thread overview]
Message-ID: <1327497161-14764-9-git-send-email-sancane@gmail.com> (raw)
In-Reply-To: <1327497161-14764-8-git-send-email-sancane@gmail.com>
g_assert statements are buggy when the last handler available
overflows the uint16_t range. This check is currently used to
evaluate if the number of requested attributes for a sevice
match with the number of attributes added in the data base.
---
plugins/gatt-example.c | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index f12fbde..f026761 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -230,10 +230,10 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID);
len = strlen(desc_out_hum);
strncpy((char *) atval, desc_out_hum, len);
- attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ attrib_db_add(adapter->adapter, h, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, len);
- g_assert(h - start_handle == svc_size);
+ g_assert(h - start_handle + 1 == svc_size);
/* Add an SDP record for the above service */
sdp_handle = attrib_create_sdp(adapter->adapter, start_handle,
@@ -298,10 +298,10 @@ static void register_manuf1_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, MANUFACTURER_SERIAL_UUID);
len = strlen(serial1);
strncpy((char *) atval, serial1, len);
- attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ attrib_db_add(adapter->adapter, h, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, len);
- g_assert(h - start_handle == svc_size);
+ g_assert(h - start_handle + 1 == svc_size);
range[0] = start_handle;
range[1] = start_handle + svc_size - 1;
@@ -362,10 +362,10 @@ static void register_manuf2_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, MANUFACTURER_SERIAL_UUID);
len = strlen(serial2);
strncpy((char *) atval, serial2, len);
- attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ attrib_db_add(adapter->adapter, h, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, len);
- g_assert(h - start_handle == svc_size);
+ g_assert(h - start_handle + 1 == svc_size);
range[0] = start_handle;
range[1] = start_handle + svc_size - 1;
@@ -412,10 +412,10 @@ static void register_vendor_service(struct gatt_example_adapter *adapter,
atval[3] = 0x64;
atval[4] = 0x6F;
atval[5] = 0x72;
- attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ attrib_db_add(adapter->adapter, h, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 6);
- g_assert(h - start_handle == svc_size);
+ g_assert(h - start_handle + 1 == svc_size);
range[0] = start_handle;
range[1] = start_handle + svc_size - 1;
@@ -500,10 +500,9 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID);
len = strlen(desc_weight);
strncpy((char *) atval, desc_weight, len);
- attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ attrib_db_add(adapter->adapter, h, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, len);
-
- g_assert(h - start_handle == svc_size);
+ g_assert(h - start_handle + 1 == svc_size);
/* Add an SDP record for the above service */
sdp_handle = attrib_create_sdp(adapter->adapter, start_handle,
--
1.7.8.4
next prev parent reply other threads:[~2012-01-25 13:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-25 13:12 GATT improvements v3 Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 1/8] gatt-service: Add support for 128-bit Bluetooth UUIDs Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 2/8] gatt-service: Move va_end just after processing the argument list Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 3/8] gatt-service: Provide service uuid in attrib_db_find_avail function Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 4/8] attrib-server: Allocate 16-bits UUIDS at the begining of the list Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 5/8] attrib-server: Set database uuids as a double linked list Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 6/8] glib-compat: Add g_list_free_full to deal with issues in old GLib versions Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 7/8] attrib-server: Allocate 128-bits UUIDs using highest available handlers Santiago Carot-Nemesio
2012-01-25 13:12 ` Santiago Carot-Nemesio [this message]
2012-02-03 8:37 ` GATT improvements v3 Santiago Carot
2012-02-03 18:48 ` Johan Hedberg
-- strict thread matches above, loose matches on Subject: below --
2012-01-25 10:03 GATT improvements v2 Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 1/8] gatt-service: Add support for 128-bit Bluetooth UUIDs Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 2/8] gatt-service: Move va_end just after processing the argument list Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 3/8] gatt-service: Provide service uuid in attrib_db_find_avail function Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 4/8] attrib-server: Allocate 16-bits UUIDS at the begining of the list Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 5/8] attrib-server: Set database uuids as a double linked list Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 6/8] glib-compat: Add g_list_free_full to deal with issues in old GLib versions Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 7/8] attrib-server: Allocate 128-bits UUIDs using highest available handlers Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 8/8] gatt-example: Fix g_assert checks when an uint16_t value overflows Santiago Carot-Nemesio
2012-01-24 11:06 GATT service improvements Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 1/8] gatt-service: Add support for 128-bit Bluetooth UUIDs Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 2/8] gatt-service: Move va_end just after processing the argument list Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 3/8] gatt-service: Provide service uuid in attrib_db_find_avail function Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 4/8] attrib-server: Allocate 16-bits UUIDS at the begining of the list Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 5/8] attrib-server: Set database uuids as a double linked list Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 6/8] glib-compat: Add g_list_free_full to deal with issues in old GLib versions Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 7/8] attrib-server: Allocate 128-bits UUIDs using highest available handlers Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 8/8] gatt-example: Fix g_assert checks when an uint16_t value overflows Santiago Carot-Nemesio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327497161-14764-9-git-send-email-sancane@gmail.com \
--to=sancane@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).