diff options
author | fionaxu <fionaxu@google.com> | 2017-06-19 23:22:29 -0700 |
---|---|---|
committer | fionaxu <fionaxu@google.com> | 2017-08-08 16:41:23 -0700 |
commit | b50183d2fd9125249ee2e35c086d89b367d7a7ac (patch) | |
tree | f2463e88288468ae6d21889bc8f2d5c9adbb7c42 | |
parent | 15658662fddeeb9fcc91855bce624a673b448bb3 (diff) | |
download | base-b50183d2fd9125249ee2e35c086d89b367d7a7ac.tar.gz |
Handle invalid destination address gracefully
Bug: 37578305
Test: runtest --path frameworks/opt/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GsmSmsDispatcherTest.java --test-method testSendTextWithInvalidDestAddr
Change-Id: I2e79acb66178586d29dc89ad018f2726ed654a85
-rw-r--r-- | telephony/java/com/android/internal/telephony/gsm/SmsMessage.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java index 582506a367d0..d4098d94ba6c 100644 --- a/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java +++ b/telephony/java/com/android/internal/telephony/gsm/SmsMessage.java @@ -278,6 +278,10 @@ public class SmsMessage extends SmsMessageBase { scAddress, destinationAddress, mtiByte, statusReportRequested, ret); + // Skip encoding pdu if error occurs when create pdu head and the error will be handled + // properly later on encodedMessage sanity check. + if (bo == null) return ret; + // User Data (and length) byte[] userData; try { @@ -420,6 +424,9 @@ public class SmsMessage extends SmsMessageBase { scAddress, destinationAddress, (byte) 0x41, // MTI = SMS-SUBMIT, // TP-UDHI = true statusReportRequested, ret); + // Skip encoding pdu if error occurs when create pdu head and the error will be handled + // properly later on encodedMessage sanity check. + if (bo == null) return ret; // TP-Data-Coding-Scheme // No class, 8 bit data @@ -451,7 +458,7 @@ public class SmsMessage extends SmsMessageBase { * @param destinationAddress the address of the destination for the message * @param mtiByte * @param ret <code>SubmitPdu</code> containing the encoded SC - * address, if applicable, and the encoded message + * address, if applicable, and the encoded message. Returns null on encode error. */ private static ByteArrayOutputStream getSubmitPduHead( String scAddress, String destinationAddress, byte mtiByte, @@ -482,6 +489,9 @@ public class SmsMessage extends SmsMessageBase { daBytes = PhoneNumberUtils.networkPortionToCalledPartyBCD(destinationAddress); + // return empty pduHead for invalid destination address + if (daBytes == null) return null; + // destination address length in BCD digits, ignoring TON byte and pad // TODO Should be better. bo.write((daBytes.length - 1) * 2 |