@@ -568,13 +568,15 @@ int lcfs_compute_fsverity_from_fd(uint8_t *digest, int fd)
568
568
// is an error if fsverity is not enabled.
569
569
int lcfs_fd_measure_fsverity (uint8_t * digest , int fd )
570
570
{
571
- char buf [sizeof (struct fsverity_digest ) + MAX_DIGEST_SIZE ];
572
- struct fsverity_digest * fsv = (struct fsverity_digest * )& buf ;
571
+ union {
572
+ struct fsverity_digest fsv ;
573
+ char buf [sizeof (struct fsverity_digest ) + MAX_DIGEST_SIZE ];
574
+ } result ;
573
575
574
576
// First, ask the kernel if the file already has fsverity; if so we just return
575
577
// that.
576
- fsv -> digest_size = MAX_DIGEST_SIZE ;
577
- int res = ioctl (fd , FS_IOC_MEASURE_VERITY , fsv );
578
+ result . fsv . digest_size = MAX_DIGEST_SIZE ;
579
+ int res = ioctl (fd , FS_IOC_MEASURE_VERITY , & result );
578
580
if (res == -1 ) {
579
581
if (errno == ENODATA || errno == EOPNOTSUPP || errno == ENOTTY ) {
580
582
// Canonicalize errno
@@ -584,11 +586,11 @@ int lcfs_fd_measure_fsverity(uint8_t *digest, int fd)
584
586
}
585
587
// The file has fsverity enabled, but with an unexpected different algorithm (e.g. sha512).
586
588
// This is going to be a weird corner case. For now, we error out.
587
- if (fsv -> digest_size != LCFS_DIGEST_SIZE ) {
589
+ if (result . fsv . digest_size != LCFS_DIGEST_SIZE ) {
588
590
return - EWRONGVERITY ;
589
591
}
590
592
591
- memcpy (digest , buf + sizeof (struct fsverity_digest ), LCFS_DIGEST_SIZE );
593
+ memcpy (digest , result . buf + sizeof (struct fsverity_digest ), LCFS_DIGEST_SIZE );
592
594
593
595
return 0 ;
594
596
}
0 commit comments