Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e297449d authored by Greg Kaiser's avatar Greg Kaiser
Browse files

gatt_api: Avoid possible NULL dereference

We move a logging statement which dereferences a NULL pointer
until after the NULL check, and expand the error message for
the NULL check to include the function name.

Test: TreeHugger
Change-Id: Ib5134b0d6b9ec5da95ee62da9412b977925000ee
parent 3b00cc75
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -625,18 +625,18 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
  tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx);
  tGATT_REG* p_reg = gatt_get_regcb(gatt_if);

  LOG(INFO) << __func__ << " conn_id=" << loghex(conn_id)
            << ", disc_type=" << +disc_type
            << ", s_handle=" << loghex(p_param->s_handle)
            << ", e_handle=" << loghex(p_param->e_handle);

  if ((p_tcb == NULL) || (p_reg == NULL) || (p_param == NULL) ||
      (disc_type >= GATT_DISC_MAX)) {
    LOG(ERROR) << "Illegal param: disc_type=" << +disc_type
    LOG(ERROR) << __func__ << " Illegal param: disc_type=" << +disc_type
               << " conn_id=" << loghex(conn_id);
    return GATT_ILLEGAL_PARAMETER;
  }

  LOG(INFO) << __func__ << " conn_id=" << loghex(conn_id)
            << ", disc_type=" << +disc_type
            << ", s_handle=" << loghex(p_param->s_handle)
            << ", e_handle=" << loghex(p_param->e_handle);

  if (!GATT_HANDLE_IS_VALID(p_param->s_handle) ||
      !GATT_HANDLE_IS_VALID(p_param->e_handle) ||
      /* search by type does not have a valid UUID param */