Skip to content

Commit

Permalink
Use signed types to prevent subtraction overflow
Browse files Browse the repository at this point in the history
The difference between the sizes could be positive or negative. Leaving
the types as unsigned means the result overflows when the difference is
negative and removing the labs() means we'll have introduced a bug. The
subtraction results in the correct value when the unsigned integer is
interpreted as a signed integer by labs().

Clang doesn't see that we're doing a subtraction and abusing the types.
It sees the result of the subtraction, an unsigned value, being passed
to an absolute value function and emits a warning which we treat as an
error.

Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
  • Loading branch information
Ryan Moeller committed Sep 18, 2019
1 parent afc8f0a commit 23d9e3b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
rep.zprl_children = 1;
rep.zprl_parity = 0;
} else {
uint64_t vdev_size;
int64_t vdev_size;

/*
* This is a mirror or RAID-Z vdev. Go through and make
Expand Down Expand Up @@ -864,7 +864,7 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
nvlist_t *cnv = child[c];
char *path;
struct stat64 statbuf;
uint64_t size = -1ULL;
int64_t size = -1ULL;
char *childtype;
int fd, err;

Expand Down Expand Up @@ -955,7 +955,7 @@ get_replication(nvlist_t *nvroot, boolean_t fatal)
* (~16MB) then report an error.
*/
if (!dontreport &&
(vdev_size != -1ULL &&
(vdev_size != -1LL &&
(labs(size - vdev_size) >
ZPOOL_FUZZ))) {
if (ret != NULL)
Expand Down

0 comments on commit 23d9e3b

Please sign in to comment.