[libcamera-devel] [PATCH v2] libcamera: controls: validate all ControlInfo values

Christian Rauch Rauch.Christian at gmx.de
Wed Sep 21 22:31:48 CEST 2022


ControlInfoMap::validate only checks the 'min' type against the ControlId
type. Extend this with checks against the 'max' type and the 'def' type,
if a default is specified. This forces the min/max bounds to have the same
type as the controlled value, but leaves the default optional.

Signed-off-by: Christian Rauch <Rauch.Christian at gmx.de>
---
 src/libcamera/controls.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index bc3db4f6..e7251507 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -701,6 +701,28 @@ bool ControlInfoMap::validate()
 				      ? ControlTypeInteger32 : id->type();
 		const ControlInfo &info = ctrl.second;

+		if (!(info.min().isArray() == info.max().isArray() &&
+		      info.min().numElements() == info.max().numElements())) {
+			LOG(Controls, Error)
+				<< "Control " << utils::hex(id->id())
+				<< " range must have the same dimension.";
+			return false;
+		}
+
+		if (info.min().type() != info.max().type()) {
+			LOG(Controls, Error)
+				<< "Control " << utils::hex(id->id())
+				<< " range types mismatch";
+			return false;
+		}
+
+		if (info.def().type() != ControlTypeNone && (info.min().type() != info.def().type())) {
+			LOG(Controls, Error)
+				<< "Control " << utils::hex(id->id())
+				<< " default value and info type mismatch";
+			return false;
+		}
+
 		if (info.min().type() != rangeType) {
 			LOG(Controls, Error)
 				<< "Control " << utils::hex(id->id())
--
2.34.1



More information about the libcamera-devel mailing list