Skip to content

Commit 929ca5e

Browse files
author
Jake Hamby
committed
Fix bug in CDMA WDP datagram handling (fixes incoming MMS).
CDMA WDP datagram handling was refactored to use the same method that handles concatenated SMS messages. WDP datagram sequence numbers start at 0, but GSM/CDMA concatenated sequence numbers start at 1. Changed SMSDispatcher.processMessagePart() to count from 0 when handling WDP datagrams. Also changed CdmaSMSDispatcher.processCdmaWapPdu() to correctly decode segment numbers > 127 (signed byte conversion bug) and to reject PDUs with an out-of-range segment number (invalid ranges are already rejected for regular concatenated messages). Bug: 5433331 Change-Id: I25c9567769de8edca789c0d1707d4916a4c46885
1 parent c5b28bd commit 929ca5e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

telephony/java/com/android/internal/telephony/SMSDispatcher.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ protected int dispatchNormalMessage(SmsMessageBase sms) {
518518
* @param address the originating address
519519
* @param referenceNumber distinguishes concatenated messages from the same sender
520520
* @param sequenceNumber the order of this segment in the message
521+
* (starting at 0 for CDMA WDP datagrams and 1 for concatenated messages).
521522
* @param messageCount the number of segments in the message
522523
* @param timestamp the service center timestamp in millis
523524
* @param destPort the destination port for the message, or -1 for no destination port
@@ -583,7 +584,11 @@ protected int processMessagePart(byte[] pdu, String address, int referenceNumber
583584
for (int i = 0; i < cursorCount; i++) {
584585
cursor.moveToNext();
585586
int cursorSequence = cursor.getInt(SEQUENCE_COLUMN);
586-
pdus[cursorSequence - 1] = HexDump.hexStringToByteArray(
587+
// GSM sequence numbers start at 1; CDMA WDP datagram sequence numbers start at 0
588+
if (!isCdmaWapPush) {
589+
cursorSequence--;
590+
}
591+
pdus[cursorSequence] = HexDump.hexStringToByteArray(
587592
cursor.getString(PDU_COLUMN));
588593

589594
// Read the destination port from the first segment (needed for CDMA WAP PDU).
@@ -593,7 +598,12 @@ protected int processMessagePart(byte[] pdu, String address, int referenceNumber
593598
}
594599
}
595600
// This one isn't in the DB, so add it
596-
pdus[sequenceNumber - 1] = pdu;
601+
// GSM sequence numbers start at 1; CDMA WDP datagram sequence numbers start at 0
602+
if (isCdmaWapPush) {
603+
pdus[sequenceNumber] = pdu;
604+
} else {
605+
pdus[sequenceNumber - 1] = pdu;
606+
}
597607

598608
// Remove the parts from the database
599609
mResolver.delete(mRawUri, where, whereArgs);

telephony/java/com/android/internal/telephony/cdma/CdmaSMSDispatcher.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,18 @@ public int dispatchMessage(SmsMessageBase smsb) {
198198
protected int processCdmaWapPdu(byte[] pdu, int referenceNumber, String address) {
199199
int index = 0;
200200

201-
int msgType = pdu[index++];
201+
int msgType = (0xFF & pdu[index++]);
202202
if (msgType != 0) {
203203
Log.w(TAG, "Received a WAP SMS which is not WDP. Discard.");
204204
return Intents.RESULT_SMS_HANDLED;
205205
}
206-
int totalSegments = pdu[index++]; // >= 1
207-
int segment = pdu[index++]; // >= 0
206+
int totalSegments = (0xFF & pdu[index++]); // >= 1
207+
int segment = (0xFF & pdu[index++]); // >= 0
208+
209+
if (segment >= totalSegments) {
210+
Log.e(TAG, "WDP bad segment #" + segment + " expecting 0-" + (totalSegments - 1));
211+
return Intents.RESULT_SMS_HANDLED;
212+
}
208213

209214
// Only the first segment contains sourcePort and destination Port
210215
int sourcePort = 0;

0 commit comments

Comments
 (0)