Merge cherrypicks of [16816453, 17570067] into sc-d2-release.

Change-Id: Iea54cbabb16aa09e085485ad87d344008ffe5a6f
diff --git a/stack/gatt/gatt_sr.cc b/stack/gatt/gatt_sr.cc
index 9fe642c..0396bb1 100644
--- a/stack/gatt/gatt_sr.cc
+++ b/stack/gatt/gatt_sr.cc
@@ -173,6 +173,9 @@
 
     if (p_rsp != NULL) {
       total_len = (p_buf->len + p_rsp->attr_value.len);
+      if (p_cmd->multi_req.variable_len) {
+        total_len += 2;
+      }
 
       if (total_len > mtu) {
         /* just send the partial response for the overflow case */
diff --git a/stack/l2cap/l2c_ble.cc b/stack/l2cap/l2c_ble.cc
index 16454a5..d548679 100644
--- a/stack/l2cap/l2c_ble.cc
+++ b/stack/l2cap/l2c_ble.cc
@@ -621,7 +621,7 @@
       break;
     }
     case L2CAP_CMD_CREDIT_BASED_CONN_RES:
-      if (p + 2 > p_pkt_end) {
+      if (p + 8 > p_pkt_end) {
         LOG(ERROR) << "invalid L2CAP_CMD_CREDIT_BASED_CONN_RES len";
         return;
       }