[libcamera-devel] libcamera: controls: validate all ControlInfo values
diff mbox series

Message ID 20220912205705.83029-1-Rauch.Christian@gmx.de
State Superseded
Headers show
Series
  • [libcamera-devel] libcamera: controls: validate all ControlInfo values
Related show

Commit Message

Christian Rauch Sept. 12, 2022, 8:57 p.m. UTC
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@gmx.de>
---
 src/libcamera/controls.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

--
2.34.1

Patch
diff mbox series

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

+		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())