All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v3 2/4] client: Fix writing attribute values
Date: Thu, 26 Apr 2018 14:31:58 +0200	[thread overview]
Message-ID: <20180426123200.3916-2-grzegorz.kolodziejczyk@codecoup.pl> (raw)
In-Reply-To: <20180426123200.3916-1-grzegorz.kolodziejczyk@codecoup.pl>

Attribute values is not copied with dbus_message_iter_get_fixed_array,
so gatt write callback needs to replace old value with reallocation and
copy.
---
 client/gatt.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/client/gatt.c b/client/gatt.c
index 52a999dc9..b0ef7b9c0 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -1589,12 +1589,26 @@ static DBusMessage *chrc_read_value(DBusConnection *conn, DBusMessage *msg,
 static int parse_value_arg(DBusMessageIter *iter, uint8_t **value, int *len)
 {
 	DBusMessageIter array;
+	uint16_t offset = 0;
+	uint8_t *read_value;
+	int read_len;
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
 		return -EINVAL;
 
 	dbus_message_iter_recurse(iter, &array);
-	dbus_message_iter_get_fixed_array(&array, value, len);
+	dbus_message_iter_get_fixed_array(&array, &read_value, &read_len);
+
+	dbus_message_iter_next(iter);
+	if (parse_options(iter, &offset, NULL, NULL, NULL))
+		return -EINVAL;
+
+	if ((offset + read_len) > *len) {
+		*len = offset + read_len;
+		*value = g_realloc(*value, *len);
+	}
+
+	memcpy(*value + offset, read_value, read_len);
 
 	return 0;
 }
-- 
2.13.6


  reply	other threads:[~2018-04-26 12:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 12:31 [PATCH BlueZ v3 1/4] tools/hcitool: Change connection handle condition for lecup Grzegorz Kolodziejczyk
2018-04-26 12:31 ` Grzegorz Kolodziejczyk [this message]
2018-04-26 12:31 ` [PATCH BlueZ v3 3/4] client: Add support for optional gatt read offset parameter Grzegorz Kolodziejczyk
2018-04-26 12:32 ` [PATCH BlueZ v3 4/4] client: Add support for optional gatt write " Grzegorz Kolodziejczyk
2018-04-26 12:58 ` [PATCH BlueZ v3 1/4] tools/hcitool: Change connection handle condition for lecup Luiz Augusto von Dentz

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=20180426123200.3916-2-grzegorz.kolodziejczyk@codecoup.pl \
    --to=grzegorz.kolodziejczyk@codecoup.pl \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.