[libcamera-devel,v3,6/6] qcam: Check that camera can generate configuration from roles

Message ID 20200501023432.90032-7-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • {cam, qcam}: Unify stream option parsing
Related show

Commit Message

Niklas Söderlund May 1, 2020, 2:34 a.m. UTC
If the camera can not generate a configuration from the requested roles
it returns a nullptr which leads to a nullptr dereference. Fix this by
adding a check that the camera generated a configuration before trying
to access it.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/qcam/main_window.cpp | 4 ++++
 1 file changed, 4 insertions(+)

Patch

diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 74427592ea47de28..b9348111dfa28914 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -296,6 +296,10 @@  int MainWindow::startCapture()
 
 	/* Configure the camera. */
 	config_ = camera_->generateConfiguration(roles);
+	if (!config_) {
+		qWarning() << "Failed to generate configuration from roles";
+		return -EINVAL;
+	}
 
 	StreamConfiguration &cfg = config_->at(0);