Message ID | 3692da31440104c890e59b8450e4a6472f3eded8.1741047738.git.alison.schofield@intel.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Address Coverity Scan Defects | expand |
On 3/3/25 5:37 PM, alison.schofield@intel.com wrote: > From: Alison Schofield <alison.schofield@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.schofield@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > ndctl/namespace.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/ndctl/namespace.c b/ndctl/namespace.c > index 40bcf4ca65ac..3224c9ff4444 100644 > --- a/ndctl/namespace.c > +++ b/ndctl/namespace.c > @@ -2086,7 +2086,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); >
diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 40bcf4ca65ac..3224c9ff4444 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -2086,7 +2086,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);