Merge pull request #1821 from mcginty/mms-npe

prevent MMS notification NPE
This commit is contained in:
Moxie Marlinspike 2014-08-11 11:08:44 -07:00
commit b80593b5f5
2 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,28 @@
package org.thoughtcrime.securesms.service;
import android.content.Intent;
import android.test.InstrumentationTestCase;
import static org.fest.assertions.api.Assertions.*;
public class MmsReceiverTest extends InstrumentationTestCase {
private MmsReceiver mmsReceiver;
public void setUp() throws Exception {
super.setUp();
mmsReceiver = new MmsReceiver(getInstrumentation().getContext());
}
public void tearDown() throws Exception {
}
public void testProcessMalformedData() throws Exception {
Intent intent = new Intent();
intent.setAction(SendReceiveService.RECEIVE_MMS_ACTION);
intent.putExtra("data", new byte[]{0x00});
mmsReceiver.process(null, intent);
}
}

View File

@ -58,7 +58,7 @@ public class MmsReceiver {
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) {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context); MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd)pdu); Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd)pdu);