[libcamera-devel,2/2] android: CameraDevice: Validate buffer_handle by CameraBuffer::isValid()
diff mbox series

Message ID 20210405040424.1929737-3-hiroh@chromium.org
State Superseded
Headers show
Series
  • Check a buffer validness by CameraBuffer::IsValid()
Related show

Commit Message

Hirokazu Honda April 5, 2021, 4:04 a.m. UTC
This adds a validation to buffer_handle provided in
CameraDevice::processCaptureRequest() by using
CameraBuffer::isValid().

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_device.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Jacopo Mondi April 6, 2021, 12:51 p.m. UTC | #1
Hi Hiro,

On Mon, Apr 05, 2021 at 01:04:24PM +0900, Hirokazu Honda wrote:
> This adds a validation to buffer_handle provided in
> CameraDevice::processCaptureRequest() by using
> CameraBuffer::isValid().
>
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  src/android/camera_device.cpp | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 89044efa..0fff5927 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -257,6 +257,7 @@ void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,
>  }
>
>  bool isValidRequest(camera3_capture_request_t *camera3Request)
> +

Ups

>  {
>  	if (!camera3Request) {
>  		LOG(HAL, Error) << "No capture request provided";
> @@ -293,6 +294,13 @@ bool isValidRequest(camera3_capture_request_t *camera3Request)
>  				<< ") in buffer " << i;
>  			return false;
>  		}
> +
> +		CameraBuffer cameraBuffer(*outputBuffer.buffer,
> +					  PROT_READ | PROT_WRITE, /*map=*/false);
> +		if (!cameraBuffer.isValid()) {
> +			LOG(HAL, Error) << "cameraBuffer is invalid";
> +			return false;
> +		}

See comment in 1/2. I think a static function would be better. Does a
static function works well with d-pointer ?

>  	}
>
>  	return true;
> --
> 2.31.0.208.g409f899ff0-goog
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 89044efa..0fff5927 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -257,6 +257,7 @@  void sortCamera3StreamConfigs(std::vector<Camera3StreamConfig> &unsortedConfigs,
 }
 
 bool isValidRequest(camera3_capture_request_t *camera3Request)
+
 {
 	if (!camera3Request) {
 		LOG(HAL, Error) << "No capture request provided";
@@ -293,6 +294,13 @@  bool isValidRequest(camera3_capture_request_t *camera3Request)
 				<< ") in buffer " << i;
 			return false;
 		}
+
+		CameraBuffer cameraBuffer(*outputBuffer.buffer,
+					  PROT_READ | PROT_WRITE, /*map=*/false);
+		if (!cameraBuffer.isValid()) {
+			LOG(HAL, Error) << "cameraBuffer is invalid";
+			return false;
+		}
 	}
 
 	return true;