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

Message ID 83a11c1c-c9a9-3aa7-30f4-5c0d257483b9@gmx.de
State New
Headers show
Series
  • [libcamera-devel] Fwd: [PATCH v3] libcamera: controls: validate all ControlInfo values
Related show

Commit Message

Christian Rauch Oct. 6, 2022, 6:18 p.m. UTC
Hi,

I am just forwarding this again to see if there is more feedback or
interest in merging this in the medium-term.

Best,
Christian


-------- Weitergeleitete Nachricht --------
Betreff: [PATCH v3] libcamera: controls: validate all ControlInfo values
Datum: Thu, 22 Sep 2022 22:22:13 +0200
Von: Christian Rauch <Rauch.Christian@gmx.de>
An: libcamera-devel@lists.libcamera.org
Kopie (CC): Christian Rauch <Rauch.Christian@gmx.de>, Kieran Bingham
<kieran.bingham@ideasonboard.com>

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>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
  src/libcamera/controls.cpp | 25 ++++++++++++++++++++++++-
  1 file changed, 24 insertions(+), 1 deletion(-)

--
2.34.1

Patch
diff mbox series

diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index bc3db4f6..1e54a712 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -701,9 +701,32 @@  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 " << id->name()
+				<< " range must have the same dimension.";
+			return false;
+		}
+
+		if (info.min().type() != info.max().type()) {
+			LOG(Controls, Error)
+				<< "Control " << id->name()
+				<< " range types mismatch";
+			return false;
+		}
+
+		if (info.def().type() != ControlTypeNone &&
+			info.min().type() != info.def().type()) {
+			LOG(Controls, Error)
+				<< "Control " << id->name()
+				<< " default value and info type mismatch";
+			return false;
+		}
+
  		if (info.min().type() != rangeType) {
  			LOG(Controls, Error)
-				<< "Control " << utils::hex(id->id())
+				<< "Control " << id->name()
  				<< " type and info type mismatch";
  			return false;
  		}