OSDN Git Service

Null terminate MAP instance information
authorAjay Panicker <apanicke@google.com>
Fri, 8 Jan 2016 00:05:11 +0000 (16:05 -0800)
committerAndre Eisenbach <eisenbach@google.com>
Thu, 18 Feb 2016 18:55:25 +0000 (10:55 -0800)
Bug: 26437927
Change-Id: I673de7f7c68b9a02b234bb99c6f89c7fc36f90c9

src/com/android/bluetooth/map/BluetoothMapUtils.java

index 66ceecc..f10c4ec 100755 (executable)
@@ -394,15 +394,16 @@ public class BluetoothMapUtils {
     static public byte[] truncateUtf8StringToBytearray(String utf8String, int maxLength)
             throws UnsupportedEncodingException {
 
-        byte[] utf8Bytes = null;
+        byte[] utf8Bytes = new byte[utf8String.length() + 1];
         try {
-            utf8Bytes = utf8String.getBytes("UTF-8");
+            System.arraycopy(utf8String.getBytes("UTF-8"), 0,
+                             utf8Bytes, 0, utf8String.length());
         } catch (UnsupportedEncodingException e) {
             Log.e(TAG,"truncateUtf8StringToBytearray: getBytes exception ", e);
             throw e;
         }
 
-        if (utf8Bytes.length > (maxLength - 1)) {
+        if (utf8Bytes.length > maxLength) {
             /* if 'continuation' byte is in place 200,
              * then strip previous bytes until utf-8 start byte is found */
             if ( (utf8Bytes[maxLength - 1] & 0xC0) == 0x80 ) {