summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuhrid Subramaniam <suhrid.subramaniam@mediatek.com>2023-03-02 11:06:29 -0800
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2023-03-09 18:40:40 +0200
commit16546269aa2a725d5fd187eef2dc812bbba43b7a (patch)
tree5b787c3a592de57556473fe54d98146b569a8ec7 /src
parent1957219d7e7ca557d6068fb7e46bd29b30211e6a (diff)
libcamera: converter: Check converter validity
The ConverterFactoryBase::create() function returns a nullptr when no converter is found. The only caller, SimpleCameraData::init(), checks if the converter is valid with isValid(), but doesn't check if the pointer is null, which can lead to a crash. We could check both pointer validity and converter validity in the caller, but to limit the complexity in callers, it is better to check the converter validity in the create() function and return a null pointer when no valid converter is found. Signed-off-by: Suhrid Subramaniam <suhrid.subramaniam@mediatek.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/converter.cpp4
-rw-r--r--src/libcamera/pipeline/simple/simple.cpp2
2 files changed, 4 insertions, 2 deletions
diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp
index 3de39cff..fa0f1ec8 100644
--- a/src/libcamera/converter.cpp
+++ b/src/libcamera/converter.cpp
@@ -227,7 +227,9 @@ std::unique_ptr<Converter> ConverterFactoryBase::create(MediaDevice *media)
<< factory->name_ << " factory with "
<< (it == compatibles.end() ? "no" : media->driver()) << " alias.";
- return factory->createInstance(media);
+ std::unique_ptr<Converter> converter = factory->createInstance(media);
+ if (converter->isValid())
+ return converter;
}
return nullptr;
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 24ded4db..2423ec10 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -493,7 +493,7 @@ int SimpleCameraData::init()
MediaDevice *converter = pipe->converter();
if (converter) {
converter_ = ConverterFactoryBase::create(converter);
- if (!converter_->isValid()) {
+ if (!converter_) {
LOG(SimplePipeline, Warning)
<< "Failed to create converter, disabling format conversion";
converter_.reset();