[libcamera-devel] [PATCH v4 4/9] libcamera: yaml_parser: Fix bounds checking for 16-bit YamlObject::get()

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Aug 16 03:54:09 CEST 2022


The YamlObject::get() function specializations for 16-bit integers cast
the return value of strto(u)l() to a 16-bit integer, rendering the
bounds checking useless. Fix them.

Fixes: c7d260c03abd ("libcamera: yaml_parser: Add get() specializations for 16-bit integers")
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/yaml_parser.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp
index 9162e2250ed4..f928b7238a19 100644
--- a/src/libcamera/yaml_parser.cpp
+++ b/src/libcamera/yaml_parser.cpp
@@ -143,7 +143,7 @@ std::optional<int16_t> YamlObject::get() const
 	char *end;
 
 	errno = 0;
-	int16_t value = std::strtol(value_.c_str(), &end, 10);
+	long value = std::strtol(value_.c_str(), &end, 10);
 
 	if ('\0' != *end || errno == ERANGE ||
 	    value < std::numeric_limits<int16_t>::min() ||
@@ -176,7 +176,7 @@ std::optional<uint16_t> YamlObject::get() const
 	char *end;
 
 	errno = 0;
-	uint16_t value = std::strtoul(value_.c_str(), &end, 10);
+	unsigned long value = std::strtoul(value_.c_str(), &end, 10);
 
 	if ('\0' != *end || errno == ERANGE ||
 	    value < std::numeric_limits<uint16_t>::min() ||
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list