Fix potential NPEs in PduParser.parsePartHeaders Add null checks for contentDisposition, filename, and Content-Transfer-Encoding headers to prevent NullPointerExceptions. Bug: 513581389 Test: m ApiDemos Flag: EXEMPT BUGFIX Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:421c62127bdaa7bf5ee87205cb573f5f0fdafb52 Merged-In: Ia8ea444778992ac7a3c2cdfab855e3b1f7e9c53f Change-Id: Ia8ea444778992ac7a3c2cdfab855e3b1f7e9c53f
diff --git a/samples/ApiDemos/src/com/example/android/mmslib/pdu/PduParser.java b/samples/ApiDemos/src/com/example/android/mmslib/pdu/PduParser.java index e06e517..175fb05 100755 --- a/samples/ApiDemos/src/com/example/android/mmslib/pdu/PduParser.java +++ b/samples/ApiDemos/src/com/example/android/mmslib/pdu/PduParser.java
@@ -1681,8 +1681,11 @@ } else { pduDataStream.reset(); /* Token-text */ - part.setContentDisposition(parseWapString(pduDataStream - , TYPE_TEXT_STRING)); + byte[] contentDisposition = parseWapString(pduDataStream + , TYPE_TEXT_STRING); + if (null != contentDisposition) { + part.setContentDisposition(contentDisposition); + } } /* get filename parameter and skip other parameters */ @@ -1690,8 +1693,11 @@ if (thisStartPos - thisEndPos < len) { value = pduDataStream.read(); if (value == PduPart.P_FILENAME) { //filename is text-string - part.setFilename(parseWapString(pduDataStream - , TYPE_TEXT_STRING)); + byte[] filename = parseWapString(pduDataStream + , TYPE_TEXT_STRING); + if (null != filename) { + part.setFilename(filename); + } } /* skip other parameters */ @@ -1724,7 +1730,7 @@ byte[] tempValue = parseWapString(pduDataStream, TYPE_TEXT_STRING); // Check the header whether it is "Content-Transfer-Encoding". - if (true == + if (null != tempHeader && null != tempValue && PduPart.CONTENT_TRANSFER_ENCODING.equalsIgnoreCase(new String(tempHeader))) { part.setContentTransferEncoding(tempValue); }