From: Alison Schofield <alison.schofi...@intel.com>

A coverity scan highlighted an integer underflow when param.align
is 0, and an integer overflow when the parsing of param.align fails
and returns ULLONG_MAX.

Add explicit checks for both values.

Signed-off-by: Alison Schofield <alison.schofi...@intel.com>
Reviewed-by: Dave Jiang <dave.ji...@intel.com>
---
 ndctl/namespace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 2cee1c4c1451..e443130a5a93 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -2087,7 +2087,11 @@ static int namespace_rw_infoblock(struct ndctl_namespace 
*ndns,
                        unsigned long long size = parse_size64(param.size);
                        align = parse_size64(param.align);
 
-                       if (align < ULLONG_MAX && !IS_ALIGNED(size, align)) {
+                       if (align == 0 || align == ULLONG_MAX) {
+                               error("invalid alignment:%s\n", param.align);
+                               rc = -EINVAL;
+                       }
+                       if (!IS_ALIGNED(size, align)) {
                                error("--size=%s not aligned to %s\n", 
param.size,
                                        param.align);
 
-- 
2.37.3


Reply via email to