diff --git a/module/os/freebsd/zfs/zio_crypt.c b/module/os/freebsd/zfs/zio_crypt.c index 024a931d78..74755eb6d9 100644 --- a/module/os/freebsd/zfs/zio_crypt.c +++ b/module/os/freebsd/zfs/zio_crypt.c @@ -1338,19 +1338,14 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf, * authenticate it. */ if (txtype == TX_WRITE) { - crypt_len = sizeof (lr_write_t) - - sizeof (lr_t) - sizeof (blkptr_t); - dst_iovecs[vec].iov_base = (char *)dlrp + - sizeof (lr_t); + const size_t o = offsetof(lr_write_t, lr_blkptr); + crypt_len = o - sizeof (lr_t); + dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t); dst_iovecs[vec].iov_len = crypt_len; /* copy the bp now since it will not be encrypted */ - memcpy(dlrp + sizeof (lr_write_t) - sizeof (blkptr_t), - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); - memcpy(aadp, - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); + memcpy(dlrp + o, slrp + o, sizeof (blkptr_t)); + memcpy(aadp, slrp + o, sizeof (blkptr_t)); aadp += sizeof (blkptr_t); aad_len += sizeof (blkptr_t); vec++; @@ -1379,8 +1374,7 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf, total_len += crypt_len; } else { crypt_len = lr_len - sizeof (lr_t); - dst_iovecs[vec].iov_base = (char *)dlrp + - sizeof (lr_t); + dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t); dst_iovecs[vec].iov_len = crypt_len; vec++; total_len += crypt_len; diff --git a/module/os/linux/zfs/zio_crypt.c b/module/os/linux/zfs/zio_crypt.c index 775ab8efbc..55f807ccfc 100644 --- a/module/os/linux/zfs/zio_crypt.c +++ b/module/os/linux/zfs/zio_crypt.c @@ -1513,20 +1513,16 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf, * authenticate it. */ if (txtype == TX_WRITE) { - crypt_len = sizeof (lr_write_t) - - sizeof (lr_t) - sizeof (blkptr_t); + const size_t o = offsetof(lr_write_t, lr_blkptr); + crypt_len = o - sizeof (lr_t); src_iovecs[nr_iovecs].iov_base = slrp + sizeof (lr_t); src_iovecs[nr_iovecs].iov_len = crypt_len; dst_iovecs[nr_iovecs].iov_base = dlrp + sizeof (lr_t); dst_iovecs[nr_iovecs].iov_len = crypt_len; /* copy the bp now since it will not be encrypted */ - memcpy(dlrp + sizeof (lr_write_t) - sizeof (blkptr_t), - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); - memcpy(aadp, - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); + memcpy(dlrp + o, slrp + o, sizeof (blkptr_t)); + memcpy(aadp, slrp + o, sizeof (blkptr_t)); aadp += sizeof (blkptr_t); aad_len += sizeof (blkptr_t); nr_iovecs++;