Fix camera ID validation

Check for id being <0 before checking its upper boundary

Change-Id: I92ed1ac78f35b5d6bbdd24cc041b2cfb4c121c74
This commit is contained in:
Vladimir Chtchetkine
2011-09-20 14:16:53 -07:00
parent 0055deec7e
commit dd63895f1f
2 changed files with 5 additions and 6 deletions

View File

@@ -123,7 +123,7 @@ int EmulatedCameraFactory::cameraDeviceOpen(int camera_id, hw_device_t** device)
return -EINVAL;
}
if (camera_id >= getEmulatedCameraNum()) {
if (camera_id < 0 || camera_id >= getEmulatedCameraNum()) {
LOGE("%s: Camera id %d is out of bounds (%d)",
__FUNCTION__, camera_id, getEmulatedCameraNum());
return -EINVAL;
@@ -141,7 +141,7 @@ int EmulatedCameraFactory::getCameraInfo(int camera_id, struct camera_info* info
return -EINVAL;
}
if (camera_id >= getEmulatedCameraNum()) {
if (camera_id < 0 || camera_id >= getEmulatedCameraNum()) {
LOGE("%s: Camera id %d is out of bounds (%d)",
__FUNCTION__, camera_id, getEmulatedCameraNum());
return -EINVAL;

View File

@@ -50,11 +50,10 @@ status_t EmulatedFakeCamera::Initialize()
}
/* Fake camera facing is defined by the qemu.sf.fake_camera boot property. */
const char* facing = EmulatedCamera::FACING_BACK;
char prop[PROPERTY_VALUE_MAX];
if (property_get("qemu.sf.fake_camera", prop, NULL) > 0) {
facing = prop;
}
property_get("qemu.sf.fake_camera", prop, EmulatedCamera::FACING_BACK);
const char* facing = prop;
mParameters.set(EmulatedCamera::FACING_KEY, facing);
LOGD("%s: Fake camera is facing %s", __FUNCTION__, facing);