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

Message ID 20220816015414.7462-5-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Add DPF tuning support for RkISP1
Related show

Commit Message

Laurent Pinchart Aug. 16, 2022, 1:54 a.m. UTC
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@ideasonboard.com>
---
 src/libcamera/yaml_parser.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Nicolas Dufresne via libcamera-devel Aug. 18, 2022, 12:12 p.m. UTC | #1
On Tue, Aug 16, 2022 at 04:54:09AM +0300, Laurent Pinchart via libcamera-devel wrote:
> 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@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@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
>
Jacopo Mondi Aug. 18, 2022, 1:03 p.m. UTC | #2
Hi Laurent

On Tue, Aug 16, 2022 at 04:54:09AM +0300, Laurent Pinchart via libcamera-devel wrote:
> 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@ideasonboard.com>

Good catch!
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> ---
>  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
>

Patch
diff mbox series

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