From b61e7839f46b631a0f471938db353fd7e70fade7 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Sun, 10 Aug 2014 13:57:42 -0700 Subject: [PATCH] prevent MMS notification NPE // FREEBIE --- .../securesms/service/MmsReceiverTest.java | 28 +++++++++++++++++++ .../securesms/service/MmsReceiver.java | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 androidTest/org/thoughtcrime/securesms/service/MmsReceiverTest.java diff --git a/androidTest/org/thoughtcrime/securesms/service/MmsReceiverTest.java b/androidTest/org/thoughtcrime/securesms/service/MmsReceiverTest.java new file mode 100644 index 0000000000..9b81712126 --- /dev/null +++ b/androidTest/org/thoughtcrime/securesms/service/MmsReceiverTest.java @@ -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); + } + +} diff --git a/src/org/thoughtcrime/securesms/service/MmsReceiver.java b/src/org/thoughtcrime/securesms/service/MmsReceiver.java index e51cea39da..4a5d6a3069 100644 --- a/src/org/thoughtcrime/securesms/service/MmsReceiver.java +++ b/src/org/thoughtcrime/securesms/service/MmsReceiver.java @@ -58,7 +58,7 @@ public class MmsReceiver { PduParser parser = new PduParser(mmsData); 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); Pair messageAndThreadId = database.insertMessageInbox((NotificationInd)pdu);