shared/gatt-server: Fix att length check logic 57/291057/2 accepted/tizen/unified/20230427.155828
authorWootak Jung <wootak.jung@samsung.com>
Fri, 7 Apr 2023 05:50:34 +0000 (14:50 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 11 Apr 2023 00:09:06 +0000 (09:09 +0900)
Change-Id: Ia5d5e43d20ad952c5a993398ab8dea42529a6162
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/shared/gatt-server.c

index 714f217..9aed2ec 100644 (file)
@@ -867,9 +867,18 @@ static void write_cb(struct bt_att_chan *chan, uint8_t opcode, const void *pdu,
                                (opcode == BT_ATT_OP_WRITE_REQ) ? "Req" : "Cmd",
                                handle);
 
+#if defined TIZEN_FEATURE_BLUEZ_MODIFY
+       /* Because the length includes handle 2bytes,
+        * 'length - 2' should be delivered when checking att length
+        */
+       ecode = check_length(length - 2, 0);
+       if (ecode)
+               goto error;
+#else
        ecode = check_length(length, 0);
        if (ecode)
                goto error;
+#endif
 
        ecode = check_permissions(server, attr, BT_ATT_PERM_WRITE_MASK);
        if (ecode)
@@ -1449,9 +1458,18 @@ static void prep_write_cb(struct bt_att_chan *chan, uint8_t opcode,
        util_debug(server->debug_callback, server->debug_data,
                                "Prep Write Req - handle: 0x%04x", handle);
 
+#if defined TIZEN_FEATURE_BLUEZ_MODIFY
+       /* Because the length includes handle 2bytes and offset 2bytes,
+        * 'length - 4' should be delivered when checking att length
+        */
+       ecode = check_length(length - 4, offset);
+       if (ecode)
+               goto error;
+#else
        ecode = check_length(length, offset);
        if (ecode)
                goto error;
+#endif
 
        ecode = check_permissions(server, attr, BT_ATT_PERM_WRITE_MASK);
        if (ecode)