[RFC PATCH v2 06/13] libcamera: simple: Protect against null maxPipeConfig

Milan Zamazal mzamazal at redhat.com
Fri Jan 24 22:57:57 CET 2025


SimpleCameraData::pipeConfig_ is set to the determined maxPipeConfig if
no better configuration is found.  In the current code, maxPipeConfig
should be always set.  But it may be easy to miss that requirement and
end up with null maxPipeConfig on contingent code changes.

Let's add a check for nullptr to prevent segmentation fault surprises.
It doesn't harm.

Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
 src/libcamera/pipeline/simple/simple.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index e6bbff5d..300ebbc0 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -1078,8 +1078,13 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
 	}
 
 	/* If no configuration was large enough, select the largest one. */
-	if (!pipeConfig_)
+	if (!pipeConfig_) {
+		if (!maxPipeConfig) {
+			LOG(SimplePipeline, Error) << "No valid configuration found";
+			return Invalid;
+		}
 		pipeConfig_ = maxPipeConfig;
+	}
 
 	LOG(SimplePipeline, Debug)
 		<< "Picked "
-- 
2.48.1



More information about the libcamera-devel mailing list