Browse Source

msm8976-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
changes/65/226765/3
Paul Keith 5 years ago committed by LuK1337
parent
commit
d0f4c54641
  1. 60
      ril/libril/ril_service.cpp

60
ril/libril/ril_service.cpp

@ -2984,7 +2984,7 @@ int responseIntOrEmpty(RadioResponseInfo& responseInfo, int serial, int response @@ -2984,7 +2984,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 {
@ -2999,7 +2999,7 @@ int responseInt(RadioResponseInfo& responseInfo, int serial, int responseType, R @@ -2999,7 +2999,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 {
@ -3448,13 +3448,13 @@ int radio::getLastCallFailCauseResponse(int slotId, @@ -3448,13 +3448,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;
@ -3807,7 +3807,7 @@ int radio::getVoiceRegistrationStateResponse(int slotId, @@ -3807,7 +3807,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 {
@ -3820,7 +3820,7 @@ int radio::getVoiceRegistrationStateResponse(int slotId, @@ -3820,7 +3820,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 =
@ -3870,7 +3870,7 @@ int radio::getDataRegistrationStateResponse(int slotId, @@ -3870,7 +3870,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 {
@ -3880,7 +3880,7 @@ int radio::getDataRegistrationStateResponse(int slotId, @@ -3880,7 +3880,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 =
@ -3924,7 +3924,7 @@ int radio::getOperatorResponse(int slotId, @@ -3924,7 +3924,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;
@ -4191,7 +4191,7 @@ int radio::getClirResponse(int slotId, @@ -4191,7 +4191,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 {
@ -4303,7 +4303,7 @@ int radio::getCallWaitingResponse(int slotId, @@ -4303,7 +4303,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 {
@ -4480,7 +4480,7 @@ int radio::getNetworkSelectionModeResponse(int slotId, @@ -4480,7 +4480,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 {
@ -4571,7 +4571,7 @@ int radio::getAvailableNetworksResponse(int slotId, @@ -4571,7 +4571,7 @@ int radio::getAvailableNetworksResponse(int slotId,
populateResponseInfo(responseInfo, serial, responseType, e);
hidl_vec<OperatorInfo> networks;
if ((response == NULL && responseLen != 0)
|| responseLen % (qanRespStrings * sizeof(char *))!= 0) {
|| responseLen % (qanRespStrings * sizeof(char *)) != 0) {
RLOGE("getAvailableNetworksResponse Invalid response: NULL");
if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
} else {
@ -4715,7 +4715,7 @@ int radio::getMuteResponse(int slotId, @@ -4715,7 +4715,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 {
@ -5232,7 +5232,7 @@ int radio::getPreferredVoicePrivacyResponse(int slotId, @@ -5232,7 +5232,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 {
@ -5518,7 +5518,7 @@ int radio::getCDMASubscriptionResponse(int slotId, @@ -5518,7 +5518,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
@ -5598,7 +5598,7 @@ int radio::getDeviceIdentityResponse(int slotId, @@ -5598,7 +5598,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
@ -5929,7 +5929,7 @@ int radio::getImsRegistrationStateResponse(int slotId, @@ -5929,7 +5929,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 {
@ -6971,7 +6971,7 @@ int radio::newSmsStatusReportInd(int slotId, @@ -6971,7 +6971,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;
}
@ -6992,7 +6992,7 @@ int radio::newSmsOnSimInd(int slotId, int indicationType, @@ -6992,7 +6992,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;
}
@ -7368,7 +7368,7 @@ int radio::stkEventNotifyInd(int slotId, int indicationType, @@ -7368,7 +7368,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;
}
@ -7579,7 +7579,7 @@ int radio::restrictedStateChangedInd(int slotId, @@ -7579,7 +7579,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;
}
@ -7653,7 +7653,7 @@ int radio::cdmaOtaProvisionStatusInd(int slotId, @@ -7653,7 +7653,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;
}
@ -7866,7 +7866,7 @@ int radio::indicateRingbackToneInd(int slotId, @@ -7866,7 +7866,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;
}
@ -7905,7 +7905,7 @@ int radio::cdmaSubscriptionSourceChangedInd(int slotId, @@ -7905,7 +7905,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;
}
@ -7929,7 +7929,7 @@ int radio::cdmaPrlChangedInd(int slotId, @@ -7929,7 +7929,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;
}
@ -7984,7 +7984,7 @@ int radio::voiceRadioTechChangedInd(int slotId, @@ -7984,7 +7984,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;
}
@ -8195,7 +8195,7 @@ int radio::subscriptionStatusChangedInd(int slotId, @@ -8195,7 +8195,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;
}
@ -8218,7 +8218,7 @@ int radio::srvccStateNotifyInd(int slotId, @@ -8218,7 +8218,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;
}

Loading…
Cancel
Save