From dd63895f1fb79667688219bdb1d4c71fce26fbab Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Tue, 20 Sep 2011 14:16:53 -0700 Subject: [PATCH] Fix camera ID validation Check for id being <0 before checking its upper boundary Change-Id: I92ed1ac78f35b5d6bbdd24cc041b2cfb4c121c74 --- tools/emulator/system/camera/EmulatedCameraFactory.cpp | 4 ++-- tools/emulator/system/camera/EmulatedFakeCamera.cpp | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/emulator/system/camera/EmulatedCameraFactory.cpp b/tools/emulator/system/camera/EmulatedCameraFactory.cpp index 9bfc7269f..5c5c5dec1 100755 --- a/tools/emulator/system/camera/EmulatedCameraFactory.cpp +++ b/tools/emulator/system/camera/EmulatedCameraFactory.cpp @@ -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; diff --git a/tools/emulator/system/camera/EmulatedFakeCamera.cpp b/tools/emulator/system/camera/EmulatedFakeCamera.cpp index 3b6e91b4e..d82fd787f 100755 --- a/tools/emulator/system/camera/EmulatedFakeCamera.cpp +++ b/tools/emulator/system/camera/EmulatedFakeCamera.cpp @@ -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);