Bug 1519535 - Check that deviceNumber is valid in GetDeviceName; r=jib
authorDan Minor <dminor@mozilla.com>
Wed, 06 Mar 2019 15:41:35 +0000
changeset 520501 cc9a46d41684c0a60f3820ea9b8d3647df9f8767
parent 520500 8a2800ad38adc98d863bcc4effc52d84aaa105c4
child 520502 398daf04b7cf386d40475ff19abcc408f838280e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1519535
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519535 - Check that deviceNumber is valid in GetDeviceName; r=jib Differential Revision: https://phabricator.services.mozilla.com/D21945
media/webrtc/trunk/webrtc/modules/video_capture/objc/device_info.mm
--- a/media/webrtc/trunk/webrtc/modules/video_capture/objc/device_info.mm
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/objc/device_info.mm
@@ -62,17 +62,20 @@ int32_t DeviceInfoIos::Init() {
       if (support) {
         VideoCaptureCapability capability = [DeviceInfoIosObjC capabilityForPreset:preset];
         capabilityVector.push_back(capability);
       }
     }
 
     char deviceNameUTF8[256];
     char deviceId[256];
-    this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256);
+    int error = this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256);
+    if (error) {
+      return error;
+    }
     std::string deviceIdCopy(deviceId);
     std::pair<std::string, VideoCaptureCapabilities> mapPair =
         std::pair<std::string, VideoCaptureCapabilities>(deviceIdCopy, capabilityVector);
     _capabilitiesMap.insert(mapPair);
   }
 
   return 0;
 }
@@ -84,16 +87,21 @@ uint32_t DeviceInfoIos::NumberOfDevices(
 int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber,
                                      char* deviceNameUTF8,
                                      uint32_t deviceNameUTF8Length,
                                      char* deviceUniqueIdUTF8,
                                      uint32_t deviceUniqueIdUTF8Length,
                                      char* productUniqueIdUTF8,
                                      uint32_t productUniqueIdUTF8Length,
                                      pid_t* pid) {
+
+  if (deviceNumber >= NumberOfDevices()) {
+    return -1;
+  }
+
   NSString* deviceName = [DeviceInfoIosObjC deviceNameForIndex:deviceNumber];
 
   NSString* deviceUniqueId = [DeviceInfoIosObjC deviceUniqueIdForIndex:deviceNumber];
 
   strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length);
   deviceNameUTF8[deviceNameUTF8Length - 1] = '\0';
 
   strncpy(deviceUniqueIdUTF8, deviceUniqueId.UTF8String, deviceUniqueIdUTF8Length);