Message ID | 20220816015414.7462-5-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
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 >
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 >
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() ||
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(-)