msm8974-common: libril: Get off my back

* Checking numInts and numStrings for strict equality when
  we're not looping is dumb, because Samsung is notorious
  for sending extra information in their RIL
* Check if there's *enough* data rather than the *exact amount*
  to fix a bunch of invalid response errors

Change-Id: I14bc37240e5760b4629fcb74b64f25ad95d4fdfc
This commit is contained in:
Paul Keith 2018-01-04 15:42:19 +01:00 committed by Kevin F. Haggerty
parent 2d9467684d
commit 6f2f2902ee

View File

@ -2967,7 +2967,7 @@ int responseIntOrEmpty(RadioResponseInfo& responseInfo, int serial, int response
// Earlier RILs did not send a response for some cases although the interface
// expected an integer as response. Do not return error if response is empty. Instead
// Return -1 in those cases to maintain backward compatibility.
} else if (response == NULL || responseLen != sizeof(int)) {
} else if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("responseIntOrEmpty: Invalid response");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -2982,7 +2982,7 @@ int responseInt(RadioResponseInfo& responseInfo, int serial, int responseType, R
populateResponseInfo(responseInfo, serial, responseType, e);
int ret = -1;
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("responseInt: Invalid response");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -3431,13 +3431,13 @@ int radio::getLastCallFailCauseResponse(int slotId,
if (response == NULL) {
RLOGE("getCurrentCallsResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else if (responseLen == sizeof(int)) {
int *pInt = (int *) response;
info.causeCode = (LastCallFailCause) pInt[0];
} else if (responseLen == sizeof(RIL_LastCallFailCauseInfo)) {
RIL_LastCallFailCauseInfo *pFailCauseInfo = (RIL_LastCallFailCauseInfo *) response;
info.causeCode = (LastCallFailCause) pFailCauseInfo->cause_code;
info.vendorCause = convertCharPtrToHidlString(pFailCauseInfo->vendor_cause);
} else if (responseLen % sizeof(int) != 0) {
int *pInt = (int *) response;
info.causeCode = (LastCallFailCause) pInt[0];
} else {
RLOGE("getCurrentCallsResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
@ -3790,7 +3790,7 @@ int radio::getVoiceRegistrationStateResponse(int slotId,
RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else if (s_vendorFunctions->version <= 14) {
if (numStrings != 15) {
if (numStrings < 15) {
RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -3803,7 +3803,7 @@ int radio::getVoiceRegistrationStateResponse(int slotId,
voiceRegResponse.defaultRoamingIndicator = ATOI_NULL_HANDLED_DEF(resp[12], 0);
voiceRegResponse.reasonForDenial = ATOI_NULL_HANDLED_DEF(resp[13], 0);
fillCellIdentityFromVoiceRegStateResponseString(voiceRegResponse.cellIdentity,
numStrings, resp);
15, resp);
}
} else {
RIL_VoiceRegistrationStateResponse *voiceRegState =
@ -3853,7 +3853,7 @@ int radio::getDataRegistrationStateResponse(int slotId,
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else if (s_vendorFunctions->version <= 14) {
int numStrings = responseLen / sizeof(char *);
if ((numStrings != 6) && (numStrings != 11)) {
if (numStrings < 6) {
RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -3863,7 +3863,7 @@ int radio::getDataRegistrationStateResponse(int slotId,
dataRegResponse.reasonDataDenied = ATOI_NULL_HANDLED(resp[4]);
dataRegResponse.maxDataCalls = ATOI_NULL_HANDLED_DEF(resp[5], 1);
fillCellIdentityFromDataRegStateResponseString(dataRegResponse.cellIdentity,
numStrings, resp);
numStrings < 11 ? 6 : 11, resp);
}
} else {
RIL_DataRegistrationStateResponse *dataRegState =
@ -3907,7 +3907,7 @@ int radio::getOperatorResponse(int slotId,
hidl_string shortName;
hidl_string numeric;
int numStrings = responseLen / sizeof(char *);
if (response == NULL || numStrings != 3) {
if (response == NULL || numStrings < 3) {
RLOGE("getOperatorResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
@ -4174,7 +4174,7 @@ int radio::getClirResponse(int slotId,
populateResponseInfo(responseInfo, serial, responseType, e);
int n = -1, m = -1;
int numInts = responseLen / sizeof(int);
if (response == NULL || numInts != 2) {
if (response == NULL || numInts < 2) {
RLOGE("getClirResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -4286,7 +4286,7 @@ int radio::getCallWaitingResponse(int slotId,
bool enable = false;
int serviceClass = -1;
int numInts = responseLen / sizeof(int);
if (response == NULL || numInts != 2) {
if (response == NULL || numInts < 2) {
RLOGE("getCallWaitingResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -4463,7 +4463,7 @@ int radio::getNetworkSelectionModeResponse(int slotId,
RadioResponseInfo responseInfo = {};
populateResponseInfo(responseInfo, serial, responseType, e);
bool manual = false;
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("getNetworkSelectionModeResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -4698,7 +4698,7 @@ int radio::getMuteResponse(int slotId,
RadioResponseInfo responseInfo = {};
populateResponseInfo(responseInfo, serial, responseType, e);
bool enable = false;
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("getMuteResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -5215,7 +5215,7 @@ int radio::getPreferredVoicePrivacyResponse(int slotId,
populateResponseInfo(responseInfo, serial, responseType, e);
bool enable = false;
int numInts = responseLen / sizeof(int);
if (response == NULL || numInts != 1) {
if (response == NULL || numInts < 1) {
RLOGE("getPreferredVoicePrivacyResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -5501,7 +5501,7 @@ int radio::getCDMASubscriptionResponse(int slotId,
int numStrings = responseLen / sizeof(char *);
hidl_string emptyString;
if (response == NULL || numStrings != 5) {
if (response == NULL || numStrings < 5) {
RLOGE("getOperatorResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
Return<void> retStatus
@ -5581,7 +5581,7 @@ int radio::getDeviceIdentityResponse(int slotId,
int numStrings = responseLen / sizeof(char *);
hidl_string emptyString;
if (response == NULL || numStrings != 4) {
if (response == NULL || numStrings < 4) {
RLOGE("getDeviceIdentityResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
Return<void> retStatus
@ -5912,7 +5912,7 @@ int radio::getImsRegistrationStateResponse(int slotId,
bool isRegistered = false;
int ratFamily = 0;
int numInts = responseLen / sizeof(int);
if (response == NULL || numInts != 2) {
if (response == NULL || numInts < 2) {
RLOGE("getImsRegistrationStateResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -6950,7 +6950,7 @@ int radio::newSmsStatusReportInd(int slotId,
int radio::newSmsOnSimInd(int slotId, int indicationType,
int token, RIL_Errno e, void *response, size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("newSmsOnSimInd: invalid response");
return 0;
}
@ -6971,7 +6971,7 @@ int radio::newSmsOnSimInd(int slotId, int indicationType,
int radio::onUssdInd(int slotId, int indicationType,
int token, RIL_Errno e, void *response, size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != 2 * sizeof(char *)) {
if (response == NULL || responseLen < 2 * sizeof(char *)) {
RLOGE("onUssdInd: invalid response");
return 0;
}
@ -7330,7 +7330,7 @@ int radio::stkEventNotifyInd(int slotId, int indicationType,
int radio::stkCallSetupInd(int slotId, int indicationType,
int token, RIL_Errno e, void *response, size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("stkCallSetupInd: invalid response");
return 0;
}
@ -7541,7 +7541,7 @@ int radio::restrictedStateChangedInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("restrictedStateChangedInd: invalid response");
return 0;
}
@ -7615,7 +7615,7 @@ int radio::cdmaOtaProvisionStatusInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("cdmaOtaProvisionStatusInd: invalid response");
return 0;
}
@ -7828,7 +7828,7 @@ int radio::indicateRingbackToneInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("indicateRingbackToneInd: invalid response");
return 0;
}
@ -7867,7 +7867,7 @@ int radio::cdmaSubscriptionSourceChangedInd(int slotId,
int indicationType, int token, RIL_Errno e,
void *response, size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("cdmaSubscriptionSourceChangedInd: invalid response");
return 0;
}
@ -7891,7 +7891,7 @@ int radio::cdmaPrlChangedInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("cdmaPrlChangedInd: invalid response");
return 0;
}
@ -7946,7 +7946,7 @@ int radio::voiceRadioTechChangedInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("voiceRadioTechChangedInd: invalid response");
return 0;
}
@ -8157,7 +8157,7 @@ int radio::subscriptionStatusChangedInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("subscriptionStatusChangedInd: invalid response");
return 0;
}
@ -8180,7 +8180,7 @@ int radio::srvccStateNotifyInd(int slotId,
int indicationType, int token, RIL_Errno e, void *response,
size_t responseLen) {
if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
if (response == NULL || responseLen != sizeof(int)) {
if (response == NULL || responseLen % sizeof(int) != 0) {
RLOGE("srvccStateNotifyInd: invalid response");
return 0;
}