From 5ad6947b2d955a4e972d556090922d77aa6a2641 Mon Sep 17 00:00:00 2001 From: Rekha Kumar Date: Mon, 8 Aug 2011 16:02:25 -0700 Subject: Telephony: Fix MT SMS with invalid TOA field causing crash issue Throw FormatException when type of number is incorrect and handle it Change-Id: I305ea1c9e4fee29c84caefec7d7564d46228851d --- src/java/com/android/internal/telephony/gsm/GsmSmsAddress.java | 8 +++++--- src/java/com/android/internal/telephony/gsm/SmsMessage.java | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/java/com/android/internal/telephony/gsm/GsmSmsAddress.java b/src/java/com/android/internal/telephony/gsm/GsmSmsAddress.java index c163803..fa188f3 100644 --- a/src/java/com/android/internal/telephony/gsm/GsmSmsAddress.java +++ b/src/java/com/android/internal/telephony/gsm/GsmSmsAddress.java @@ -17,7 +17,7 @@ package com.android.internal.telephony.gsm; import android.telephony.PhoneNumberUtils; - +import java.text.ParseException; import com.android.internal.telephony.GsmAlphabet; import com.android.internal.telephony.SmsAddress; @@ -35,9 +35,10 @@ public class GsmSmsAddress extends SmsAddress { * @param offset the offset of the Address-Length byte * @param length the length in bytes rounded up, e.g. "2 + * (addressLength + 1) / 2" + * @throws ParseException */ - public GsmSmsAddress(byte[] data, int offset, int length) { + public GsmSmsAddress(byte[] data, int offset, int length) throws ParseException { origBytes = new byte[length]; System.arraycopy(data, offset, origBytes, 0, length); @@ -49,7 +50,8 @@ public class GsmSmsAddress extends SmsAddress { // TOA must have its high bit set if ((toa & 0x80) != 0x80) { - throw new RuntimeException("Invalid TOA - high bit must be set"); + throw new ParseException("Invalid TOA - high bit must be set. toa = " + toa, + offset + OFFSET_TOA); } if (isAlphanumeric()) { diff --git a/src/java/com/android/internal/telephony/gsm/SmsMessage.java b/src/java/com/android/internal/telephony/gsm/SmsMessage.java index 1ed1478..76a4b7f 100644 --- a/src/java/com/android/internal/telephony/gsm/SmsMessage.java +++ b/src/java/com/android/internal/telephony/gsm/SmsMessage.java @@ -29,6 +29,7 @@ import com.android.internal.telephony.SmsMessageBase; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.text.ParseException; import static com.android.internal.telephony.SmsConstants.MessageClass; import static com.android.internal.telephony.SmsConstants.ENCODING_UNKNOWN; @@ -560,7 +561,12 @@ public class SmsMessage extends SmsMessageBase { int addressLength = pdu[cur] & 0xff; int lengthBytes = 2 + (addressLength + 1) / 2; - ret = new GsmSmsAddress(pdu, cur, lengthBytes); + try { + ret = new GsmSmsAddress(pdu, cur, lengthBytes); + } catch (ParseException e) { + Log.e(LOG_TAG, e.getMessage()); + ret = null; + } cur += lengthBytes; -- cgit v1.1