From c59a656f9923a0e2fc308dabc373594e88b345d1 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Wed, 1 Feb 2017 15:27:41 -0800 Subject: CameraBase: Don't return an sp<> by reference If the server dies, the binder death callback clears out the global camera service sp<>, and any current references to it will become quite unhappy. Test: Camera CTS passes Bug: 31992879 AOSP-Change-Id: I2966bed35d0319e3f26e3d4b1b8dc08006a22348 CVE-2017-0544 Change-Id: Ib7ef455366927b0471f8fcabdd5a54e38e375d41 (cherry picked from commit 4b49489c12e6862e9a320ebcb53872e809ed20ec) --- camera/CameraBase.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'camera/CameraBase.cpp') diff --git a/camera/CameraBase.cpp b/camera/CameraBase.cpp index 5d50aa8..871dcea 100644 --- a/camera/CameraBase.cpp +++ b/camera/CameraBase.cpp @@ -65,7 +65,7 @@ namespace { // establish binder interface to camera service template -const sp& CameraBase::getCameraService() +const sp CameraBase::getCameraService() { Mutex::Autolock _l(gLock); if (gCameraService.get() == 0) { @@ -98,7 +98,7 @@ sp CameraBase::connect(int cameraId, sp c = new TCam(cameraId); sp cl = c; status_t status = NO_ERROR; - const sp& cs = getCameraService(); + const sp cs = getCameraService(); if (cs != 0) { TCamConnectService fnConnectService = TCamTraits::fnConnectService; @@ -195,7 +195,7 @@ int CameraBase::getNumberOfCameras() { template status_t CameraBase::getCameraInfo(int cameraId, struct CameraInfo* cameraInfo) { - const sp& cs = getCameraService(); + const sp cs = getCameraService(); if (cs == 0) return UNKNOWN_ERROR; return cs->getCameraInfo(cameraId, cameraInfo); } @@ -203,7 +203,7 @@ status_t CameraBase::getCameraInfo(int cameraId, template status_t CameraBase::addServiceListener( const sp& listener) { - const sp& cs = getCameraService(); + const sp cs = getCameraService(); if (cs == 0) return UNKNOWN_ERROR; return cs->addListener(listener); } @@ -211,7 +211,7 @@ status_t CameraBase::addServiceListener( template status_t CameraBase::removeServiceListener( const sp& listener) { - const sp& cs = getCameraService(); + const sp cs = getCameraService(); if (cs == 0) return UNKNOWN_ERROR; return cs->removeListener(listener); } -- cgit v1.1