Skip to content

Commit

Permalink
Fix coverity defects: CID 147534
Browse files Browse the repository at this point in the history
CID 147534: Negative array index read

Reviewed-by: Giuseppe Di Natale <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: cao.xuewen <[email protected]>
Closes openzfs#5467
  • Loading branch information
heary-cao authored and behlendorf committed Dec 16, 2016
1 parent 0101796 commit 81eb8a1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
namelen = strlen(name);
}
nameidx = us_field_index("name");
if (namelen > cb->cb_width[nameidx])
if (nameidx >= 0 && namelen > cb->cb_width[nameidx])
cb->cb_width[nameidx] = namelen;

/*
Expand Down Expand Up @@ -2574,7 +2574,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space)
return (-1);
}
sizeidx = us_field_index(propname);
if (sizelen > cb->cb_width[sizeidx])
if (sizeidx >= 0 && sizelen > cb->cb_width[sizeidx])
cb->cb_width[sizeidx] = sizelen;

if (nvlist_add_uint64(props, propname, space) != 0)
Expand Down

0 comments on commit 81eb8a1

Please sign in to comment.