Fix for NPE on null PDUs

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-04-24 17:33:17 -07:00
parent 08cf364ee6
commit d0008b57b5

View File

@ -36,6 +36,8 @@ import ws.com.google.android.mms.pdu.PduParser;
public class MmsListener extends BroadcastReceiver { public class MmsListener extends BroadcastReceiver {
private static final String TAG = MmsListener.class.getSimpleName();
private boolean isRelevant(Context context, Intent intent) { private boolean isRelevant(Context context, Intent intent) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
return false; return false;
@ -62,8 +64,10 @@ public class MmsListener extends BroadcastReceiver {
PduParser parser = new PduParser(mmsData); PduParser parser = new PduParser(mmsData);
GenericPdu pdu = parser.parse(); GenericPdu pdu = parser.parse();
if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) if (pdu == null || pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) {
Log.w(TAG, "Received Invalid notification PDU");
return false; return false;
}
NotificationInd notificationPdu = (NotificationInd)pdu; NotificationInd notificationPdu = (NotificationInd)pdu;
@ -75,14 +79,14 @@ public class MmsListener extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.w("MmsListener", "Got MMS broadcast..." + intent.getAction()); Log.w(TAG, "Got MMS broadcast..." + intent.getAction());
if ((Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION.equals(intent.getAction()) && if ((Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION.equals(intent.getAction()) &&
Util.isDefaultSmsProvider(context)) || Util.isDefaultSmsProvider(context)) ||
(Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION.equals(intent.getAction()) && (Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION.equals(intent.getAction()) &&
isRelevant(context, intent))) isRelevant(context, intent)))
{ {
Log.w("MmsListener", "Relevant!"); Log.w(TAG, "Relevant!");
ApplicationContext.getInstance(context) ApplicationContext.getInstance(context)
.getJobManager() .getJobManager()
.add(new MmsReceiveJob(context, intent.getByteArrayExtra("data"))); .add(new MmsReceiveJob(context, intent.getByteArrayExtra("data")));