wpa_supplicant(hidl): Fixed network resp handling
The string constructed needs to be corrected.
Also,
Audited all mallocs being done in the HIDL interface to
fix couple of memory leaks.
Bug: 33706511
Test: Compiles
Change-Id: I020128520f6ca13ffa0f64ba56dcad882ebc2729
diff --git a/wpa_supplicant/hidl/sta_iface.cpp b/wpa_supplicant/hidl/sta_iface.cpp
index a513260..4a93b7c 100644
--- a/wpa_supplicant/hidl/sta_iface.cpp
+++ b/wpa_supplicant/hidl/sta_iface.cpp
@@ -498,11 +498,7 @@
if (info_elements.size() > kMaxAnqpElems) {
return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
}
- uint16_t *info_elems_buf = static_cast<uint16_t *>(
- os_malloc(sizeof(uint16_t) * info_elements.size()));
- if (!info_elems_buf) {
- return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
- }
+ uint16_t info_elems_buf[kMaxAnqpElems];
uint32_t num_info_elems = 0;
for (const auto &info_element : info_elements) {
info_elems_buf[num_info_elems++] =
diff --git a/wpa_supplicant/hidl/sta_network.cpp b/wpa_supplicant/hidl/sta_network.cpp
index 226c1bd..14a8295 100644
--- a/wpa_supplicant/hidl/sta_network.cpp
+++ b/wpa_supplicant/hidl/sta_network.cpp
@@ -1321,22 +1321,17 @@
struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
// Convert the incoming parameters to a string to pass to
// wpa_supplicant.
- std::string ctrl_rsp_param;
uint32_t kc_hex_len = params.kc.size() * 2 + 1;
- char *kc_hex = (char *)malloc(kc_hex_len);
+ std::vector<char> kc_hex(kc_hex_len);
uint32_t sres_hex_len = params.sres.size() * 2 + 1;
- char *sres_hex = (char *)malloc(sres_hex_len);
- if (!kc_hex || !sres_hex) {
- return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
- }
+ std::vector<char> sres_hex(sres_hex_len);
wpa_snprintf_hex(
- kc_hex, kc_hex_len, params.kc.data(), params.kc.size());
+ kc_hex.data(), kc_hex.size(), params.kc.data(), params.kc.size());
wpa_snprintf_hex(
- sres_hex, sres_hex_len, params.sres.data(), params.sres.size());
- ctrl_rsp_param += "kc:";
- ctrl_rsp_param += kc_hex;
- ctrl_rsp_param += " sres:";
- ctrl_rsp_param += sres_hex;
+ sres_hex.data(), sres_hex.size(), params.sres.data(),
+ params.sres.size());
+ std::string ctrl_rsp_param = ":" + std::string(kc_hex.data()) + ":" +
+ std::string(sres_hex.data());
enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
struct wpa_supplicant *wpa_s = retrieveIfacePtr();
if (wpa_supplicant_ctrl_rsp_handle(
@@ -1356,28 +1351,22 @@
struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
// Convert the incoming parameters to a string to pass to
// wpa_supplicant.
- std::string ctrl_rsp_param;
uint32_t ik_hex_len = params.ik.size() * 2 + 1;
- char *ik_hex = (char *)malloc(ik_hex_len);
+ std::vector<char> ik_hex(ik_hex_len);
uint32_t ck_hex_len = params.ck.size() * 2 + 1;
- char *ck_hex = (char *)malloc(ck_hex_len);
+ std::vector<char> ck_hex(ck_hex_len);
uint32_t res_hex_len = params.res.size() * 2 + 1;
- char *res_hex = (char *)malloc(res_hex_len);
- if (!ik_hex || !ck_hex || !res_hex) {
- return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
- }
+ std::vector<char> res_hex(res_hex_len);
wpa_snprintf_hex(
- ik_hex, ik_hex_len, params.ik.data(), params.ik.size());
+ ik_hex.data(), ik_hex.size(), params.ik.data(), params.ik.size());
wpa_snprintf_hex(
- ck_hex, ck_hex_len, params.ck.data(), params.ck.size());
+ ck_hex.data(), ck_hex.size(), params.ck.data(), params.ck.size());
wpa_snprintf_hex(
- res_hex, res_hex_len, params.res.data(), params.res.size());
- ctrl_rsp_param += "ik:";
- ctrl_rsp_param += ik_hex;
- ctrl_rsp_param += "ck:";
- ctrl_rsp_param += ck_hex;
- ctrl_rsp_param += " res:";
- ctrl_rsp_param += res_hex;
+ res_hex.data(), res_hex.size(), params.res.data(),
+ params.res.size());
+ std::string ctrl_rsp_param = ":" + std::string(ik_hex.data()) + ":" +
+ std::string(ck_hex.data()) + ":" +
+ std::string(res_hex.data());
enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
struct wpa_supplicant *wpa_s = retrieveIfacePtr();
if (wpa_supplicant_ctrl_rsp_handle(
@@ -1398,14 +1387,11 @@
// Convert the incoming parameters to a string to pass to
// wpa_supplicant.
uint32_t identity_hex_len = identity.size() * 2 + 1;
- char *identity_hex = (char *)malloc(identity_hex_len);
- std::string ctrl_rsp_param;
- if (!identity_hex) {
- return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
- }
+ std::vector<char> identity_hex(identity_hex_len);
wpa_snprintf_hex(
- identity_hex, identity_hex_len, identity.data(), identity.size());
- ctrl_rsp_param = identity_hex;
+ identity_hex.data(), identity_hex.size(), identity.data(),
+ identity.size());
+ std::string ctrl_rsp_param = identity_hex.data();
enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_EAP_IDENTITY;
struct wpa_supplicant *wpa_s = retrieveIfacePtr();
if (wpa_supplicant_ctrl_rsp_handle(