From 8b48914dc35216bd3735bb767cda57fb6a00f8db Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 13 Apr 2017 20:55:03 -0700 Subject: [PATCH] Fixed incorrect parameter handling for setup data call Integers were incorrectly passed into dispatchStrings and treated as string pointers. Also did not correctly handle MVNO type NONE case. bug: 36690591 Test: Telephony sanity tests Merged-In: I1a4e0ef93ba8a1b63519d59b18f55af195ddbea2 Change-Id: I1a4e0ef93ba8a1b63519d59b18f55af195ddbea2 --- libril/ril_service.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/libril/ril_service.cpp b/libril/ril_service.cpp index 8e377ea..e4417e4 100644 --- a/libril/ril_service.cpp +++ b/libril/ril_service.cpp @@ -538,7 +538,7 @@ bool dispatchStrings(int serial, int slotId, int request, int countStrings, ...) va_start(ap, countStrings); for (int i = 0; i < countStrings; i++) { const char* str = va_arg(ap, const char *); - if (!copyHidlStringToRil(&pStrings[i], str, pRI)) { + if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI)) { va_end(ap); for (int j = 0; j < i; j++) { memsetAndFreeStrings(1, pStrings[j]); @@ -1027,13 +1027,22 @@ Return RadioImpl::sendSMSExpectMore(int32_t serial, const GsmSmsMessage& m return Void(); } -const char *convertMvnoTypeToString(MvnoType type) { +static bool convertMvnoTypeToString(MvnoType type, char *&str) { switch (type) { - case MvnoType::IMSI: return "imsi"; - case MvnoType::GID: return "gid"; - case MvnoType::SPN: return "spn"; - default: return NULL; + case MvnoType::IMSI: + str = (char *)"imsi"; + return true; + case MvnoType::GID: + str = (char *)"gid"; + return true; + case MvnoType::SPN: + str = (char *)"spn"; + return true; + case MvnoType::NONE: + str = (char *)""; + return true; } + return false; } Return RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechnology, @@ -1056,8 +1065,8 @@ Return RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechn std::to_string((int) dataProfileInfo.authType).c_str(), protocol.c_str()); } else if (s_vendorFunctions->version >= 15) { - const char *mvnoTypeStr = convertMvnoTypeToString(dataProfileInfo.mvnoType); - if (mvnoTypeStr == NULL) { + char *mvnoTypeStr = NULL; + if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) { RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL); if (pRI != NULL) { @@ -1076,11 +1085,11 @@ Return RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechn dataProfileInfo.roamingProtocol.c_str(), std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(), std::to_string(dataProfileInfo.bearerBitmap).c_str(), - BOOL_TO_INT(modemCognitive), + modemCognitive ? "1" : "0", std::to_string(dataProfileInfo.mtu).c_str(), mvnoTypeStr, dataProfileInfo.mvnoMatchData.c_str(), - BOOL_TO_INT(roamingAllowed)); + roamingAllowed ? "1" : "0"); } else { RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version); RequestInfo *pRI = android::addRequestToList(serial, mSlotId, @@ -1932,9 +1941,7 @@ Return RadioImpl::setInitialAttachApn(int32_t serial, const DataProfileInf iaa.modemCognitive = BOOL_TO_INT(modemCognitive); iaa.mtu = dataProfileInfo.mtu; - // Note that there is no need for memory allocation/free. - iaa.mvnoType = (char *) convertMvnoTypeToString(dataProfileInfo.mvnoType); - if (iaa.mvnoType == NULL) { + if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, iaa.mvnoType)) { sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS); return Void(); } @@ -2397,12 +2404,10 @@ Return RadioImpl::setDataProfile(int32_t serial, const hidl_vec