linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Skamra <mariusz.skamra@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Subject: [PATCH BlueZ] client: Update write callbacks with invalid offset error handlers
Date: Tue,  5 May 2020 10:29:01 +0200	[thread overview]
Message-ID: <20200505082901.258762-1-mariusz.skamra@codecoup.pl> (raw)

This patch adds invalid offset handlers to write callbacks of attributes.
---
 client/gatt.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/client/gatt.c b/client/gatt.c
index 416eda953..5713f8343 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -2141,6 +2141,12 @@ static void authorize_write_response(const char *input, void *user_data)
 		goto error;
 	}
 
+	if (aad->offset > chrc->value_len) {
+		err = "org.bluez.Error.InvalidOffset";
+
+		goto error;
+	}
+
 	/* Authorization check of prepare writes */
 	if (prep_authorize) {
 		reply = g_dbus_create_reply(pending_message, DBUS_TYPE_INVALID);
@@ -2272,6 +2278,11 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
 		return NULL;
 	}
 
+	if (offset > chrc->value_len)
+		return g_dbus_create_error(msg,
+				"org.bluez.Error.InvalidOffset", NULL);
+
+
 	/* Authorization check of prepare writes */
 	if (prep_authorize)
 		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -2683,6 +2694,10 @@ static DBusMessage *desc_write_value(DBusConnection *conn, DBusMessage *msg,
 		return g_dbus_create_error(msg,
 				"org.bluez.Error.InvalidArguments", NULL);
 
+	if (offset > desc->value_len)
+		return g_dbus_create_error(msg,
+				"org.bluez.Error.InvalidOffset", NULL);
+
 	if (write_value(&desc->value_len, &desc->value, value,
 					value_len, offset, desc->max_val_len))
 		return g_dbus_create_error(msg,
-- 
2.25.4


             reply	other threads:[~2020-05-05  8:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05  8:29 Mariusz Skamra [this message]
2020-05-11 13:29 ` [PATCH BlueZ] client: Update write callbacks with invalid offset error handlers Szymon Janc

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=20200505082901.258762-1-mariusz.skamra@codecoup.pl \
    --to=mariusz.skamra@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 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).