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

paul.elder at ideasonboard.com paul.elder at ideasonboard.com
Thu Aug 18 14:12:22 CEST 2022


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 at ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder 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