Bug 1170076 - Use snprintf instead of sprintf when parsing bluetooth GATT advertisement data. r=shuang
authorJocelyn Liu <joliu@mozilla.com>
Tue, 02 Jun 2015 19:58:00 -0400
changeset 269590 daf2ce357d237ba0047d7defedfc790e6aefdd6d
parent 269589 fcc5f6cc417af0558fabed8e8b19149234be832c
child 269591 bdc2ca02b0804f61585d5dfb64cfc5d776636a55
push id2540
push userwcosta@mozilla.com
push dateWed, 03 Jun 2015 20:55:41 +0000
reviewersshuang
bugs1170076
milestone41.0a1
Bug 1170076 - Use snprintf instead of sprintf when parsing bluetooth GATT advertisement data. r=shuang
dom/bluetooth/bluetooth2/BluetoothDevice.cpp
--- a/dom/bluetooth/bluetooth2/BluetoothDevice.cpp
+++ b/dom/bluetooth/bluetooth2/BluetoothDevice.cpp
@@ -380,26 +380,30 @@ BluetoothDevice::UpdatePropertiesFromAdv
             uuid[i] = aAdvData[offset++];
             uuid[i] += (aAdvData[offset++] << 8);
             dataLength -= 2;
           }
 
           char uuidStr[36];
           if (type == GAP_INCOMPLETE_UUID16 || type == GAP_COMPLETE_UUID16) {
             // Convert 16-bits UUID into string.
-            sprintf(uuidStr, "0000%04x-0000-1000-8000-00805f9b34fb", uuid[0]);
-          } else if (type == GAP_INCOMPLETE_UUID32 || type == GAP_COMPLETE_UUID32) {
+            snprintf(uuidStr, sizeof(uuidStr),
+                     "0000%04x-0000-1000-8000-00805f9b34fb", uuid[0]);
+          } else if (type == GAP_INCOMPLETE_UUID32 ||
+                     type == GAP_COMPLETE_UUID32) {
             // Convert 32-bits UUID into string.
-            sprintf(uuidStr, "%04x%04x-0000-1000-8000-00805f9b34fb",
-              uuid[1], uuid[0]);
-          } else if (type == GAP_INCOMPLETE_UUID128 || type == GAP_COMPLETE_UUID128) {
+            snprintf(uuidStr, sizeof(uuidStr),
+                     "%04x%04x-0000-1000-8000-00805f9b34fb", uuid[1], uuid[0]);
+          } else if (type == GAP_INCOMPLETE_UUID128 ||
+                     type == GAP_COMPLETE_UUID128) {
             // Convert 128-bits UUID into string.
-            sprintf(uuidStr, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
-              uuid[7], uuid[6], uuid[5], uuid[4],
-              uuid[3], uuid[2], uuid[1], uuid[0]);
+            snprintf(uuidStr, sizeof(uuidStr),
+                     "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
+                     uuid[7], uuid[6], uuid[5], uuid[4],
+                     uuid[3], uuid[2], uuid[1], uuid[0]);
           }
           nsString uuidNsString;
           uuidNsString.AssignLiteral(uuidStr);
 
           mUuids.AppendElement(uuidNsString);
         }
 
         BluetoothDeviceBinding::ClearCachedUuidsValue(this);