Skip to content

Commit

Permalink
Merge pull request #368 from cgwalters/use-c11-followup
Browse files Browse the repository at this point in the history
Fix clang warnings
  • Loading branch information
alexlarsson authored Sep 30, 2024
2 parents 41528d4 + bb466d0 commit 3ae4c15
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 95 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ jobs:
- name: Build
# focal's meson is too old for 'meson compile'
run: ninja -C build
build-latest-clang:
runs-on: ubuntu-24.04
name: "Build (24.04, clang)"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: sudo ./hacking/installdeps.sh
- name: Configure
run: env CC=clang meson setup build --werror
- name: Build
# focal's meson is too old for 'meson compile'
run: meson compile -C build
build-unit-cross:
runs-on: ubuntu-latest
name: Build on ${{ matrix.arch }}
Expand Down
15 changes: 6 additions & 9 deletions libcomposefs/lcfs-mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,20 @@ static errint_t lcfs_validate_mount_options(struct lcfs_mount_state_s *state)

static errint_t lcfs_validate_verity_fd(struct lcfs_mount_state_s *state)
{
struct {
struct fsverity_digest fsv;
char buf[MAX_DIGEST_SIZE];
} buf;
char buf[sizeof(struct fsverity_digest) + MAX_DIGEST_SIZE];
struct fsverity_digest *fsv = (struct fsverity_digest *)&buf;
int res;

if (state->expected_digest_len != 0) {
buf.fsv.digest_size = MAX_DIGEST_SIZE;
res = ioctl(state->fd, FS_IOC_MEASURE_VERITY, &buf.fsv);
fsv->digest_size = MAX_DIGEST_SIZE;
res = ioctl(state->fd, FS_IOC_MEASURE_VERITY, fsv);
if (res == -1) {
if (errno == ENODATA || errno == EOPNOTSUPP || errno == ENOTTY)
return -ENOVERITY;
return -errno;
}
if (buf.fsv.digest_size != state->expected_digest_len ||
memcmp(state->expected_digest, buf.fsv.digest,
buf.fsv.digest_size) != 0)
if (fsv->digest_size != state->expected_digest_len ||
memcmp(state->expected_digest, fsv->digest, fsv->digest_size) != 0)
return -EWRONGVERITY;
}

Expand Down
14 changes: 6 additions & 8 deletions libcomposefs/lcfs-writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,13 @@ int lcfs_compute_fsverity_from_fd(uint8_t *digest, int fd)
// position will always be reset to zero if needed.
int lcfs_fd_get_fsverity(uint8_t *digest, int fd)
{
struct {
struct fsverity_digest fsv;
char buf[MAX_DIGEST_SIZE];
} buf;
char buf[sizeof(struct fsverity_digest) + MAX_DIGEST_SIZE];
struct fsverity_digest *fsv = (struct fsverity_digest *)&buf;

// First, ask the kernel if the file already has fsverity; if so we just return
// that.
buf.fsv.digest_size = MAX_DIGEST_SIZE;
int res = ioctl(fd, FS_IOC_MEASURE_VERITY, &buf.fsv);
fsv->digest_size = MAX_DIGEST_SIZE;
int res = ioctl(fd, FS_IOC_MEASURE_VERITY, fsv);
if (res == -1) {
// Under this condition, the file didn't have fsverity enabled or the
// kernel doesn't support it at all. We need to compute it in the current process.
Expand All @@ -604,11 +602,11 @@ int lcfs_fd_get_fsverity(uint8_t *digest, int fd)
}
// The file has fsverity enabled, but with an unexpected different algorithm (e.g. sha512).
// This is going to be a weird corner case. For now, we error out.
if (buf.fsv.digest_size != LCFS_DIGEST_SIZE) {
if (fsv->digest_size != LCFS_DIGEST_SIZE) {
return -EWRONGVERITY;
}

memcpy(digest, buf.buf, LCFS_DIGEST_SIZE);
memcpy(digest, buf + sizeof(struct fsverity_digest), LCFS_DIGEST_SIZE);

return 0;
}
Expand Down
20 changes: 8 additions & 12 deletions tools/composefs-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,14 @@ int main(int argc, char **argv)
const char *bin = argv[0];
int opt;
const struct option longopts[] = {
{
name: "basedir",
has_arg: required_argument,
flag: NULL,
val: OPT_BASEDIR
},
{
name: "filter",
has_arg: required_argument,
flag: NULL,
val: OPT_FILTER
},
{ .name = "basedir",
.has_arg = required_argument,
.flag = NULL,
.val = OPT_BASEDIR },
{ .name = "filter",
.has_arg = required_argument,
.flag = NULL,
.val = OPT_FILTER },
{},
};

Expand Down
104 changes: 38 additions & 66 deletions tools/mkcomposefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,72 +1475,44 @@ static void usage(const char *argv0)
int main(int argc, char **argv)
{
const struct option longopts[] = {
{
name: "skip-xattrs",
has_arg: no_argument,
flag: NULL,
val: OPT_SKIP_XATTRS
},
{
name: "user-xattrs",
has_arg: no_argument,
flag: NULL,
val: OPT_USER_XATTRS
},
{
name: "skip-devices",
has_arg: no_argument,
flag: NULL,
val: OPT_SKIP_DEVICES
},
{
name: "use-epoch",
has_arg: no_argument,
flag: NULL,
val: OPT_USE_EPOCH
},
{
name: "digest-store",
has_arg: required_argument,
flag: NULL,
val: OPT_DIGEST_STORE
},
{
name: "print-digest",
has_arg: no_argument,
flag: NULL,
val: OPT_PRINT_DIGEST
},
{
name: "print-digest-only",
has_arg: no_argument,
flag: NULL,
val: OPT_PRINT_DIGEST_ONLY
},
{
name: "from-file",
has_arg: no_argument,
flag: NULL,
val: OPT_FROM_FILE
},
{
name: "max-version",
has_arg: required_argument,
flag: NULL,
val: OPT_MAX_VERSION
},
{
name: "min-version",
has_arg: required_argument,
flag: NULL,
val: OPT_MIN_VERSION
},
{
name: "threads",
has_arg: required_argument,
flag: NULL,
val: OPT_THREADS
},
{ .name = "skip-xattrs",
.has_arg = no_argument,
.flag = NULL,
.val = OPT_SKIP_XATTRS },
{ .name = "user-xattrs",
.has_arg = no_argument,
.flag = NULL,
.val = OPT_USER_XATTRS },
{ .name = "skip-devices",
.has_arg = no_argument,
.flag = NULL,
.val = OPT_SKIP_DEVICES },
{ .name = "use-epoch", .has_arg = no_argument, .flag = NULL, .val = OPT_USE_EPOCH },
{ .name = "digest-store",
.has_arg = required_argument,
.flag = NULL,
.val = OPT_DIGEST_STORE },
{ .name = "print-digest",
.has_arg = no_argument,
.flag = NULL,
.val = OPT_PRINT_DIGEST },
{ .name = "print-digest-only",
.has_arg = no_argument,
.flag = NULL,
.val = OPT_PRINT_DIGEST_ONLY },
{ .name = "from-file", .has_arg = no_argument, .flag = NULL, .val = OPT_FROM_FILE },
{ .name = "max-version",
.has_arg = required_argument,
.flag = NULL,
.val = OPT_MAX_VERSION },
{ .name = "min-version",
.has_arg = required_argument,
.flag = NULL,
.val = OPT_MIN_VERSION },
{ .name = "threads",
.has_arg = required_argument,
.flag = NULL,
.val = OPT_THREADS },
{},
};
struct lcfs_write_options_s options = { 0 };
Expand Down

0 comments on commit 3ae4c15

Please sign in to comment.