Skip to content

eBPF-based security platform

shirudo-build: follow the kernel coding style

Daniel Borkmanne5b8a62fd3b4
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index 05067a7d..bc205ccf 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -153,11 +153,20 @@ static int build_parse_string(const char *value, char *out, size_t cap)
if (c == '\\' && quote == '"') {
c = (unsigned char)*p++;
switch (c) {
- case 'n': c = '\n'; break;
- case 'r': c = '\r'; break;
- case 't': c = '\t'; break;
- case '\\': case '"': break;
- default: return -EINVAL;
+ case 'n':
+ c = '\n';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ case '\\':
+ case '"':
+ break;
+ default:
+ return -EINVAL;
}
}
if (n + 1 >= cap)
@@ -272,10 +281,11 @@ static int build_parse_selector_kv(const char *key, const char *value,
}
if (!key_len || key_len >= SHIRUDO_TREE_STRING_MAX)
return -EINVAL;
- for (int i = 0; i < *n; i++)
+ for (int i = 0; i < *n; i++) {
if (strlen(kvs[i].key) == key_len &&
!strncmp(kvs[i].key, key, key_len))
return -EEXIST;
+ }
if (*n >= max)
return -E2BIG;
kv = &kvs[*n];
@@ -295,9 +305,10 @@ static bool build_name_ok(const char *s)
if (!s || !*s || !isalnum((unsigned char)s[0]) || strlen(s) >= 128)
return false;
- for (; *p; p++)
+ for (; *p; p++) {
if (!(isalnum(*p) || *p == '.' || *p == '_' || *p == '-'))
return false;
+ }
return true;
}
@@ -307,9 +318,10 @@ static bool build_version_ok(const char *s)
if (!s || !*s || !isalnum((unsigned char)s[0]) || strlen(s) >= 128)
return false;
- for (; *p; p++)
+ for (; *p; p++) {
if (!(isalnum(*p) || *p == '.' || *p == '_' || *p == '-' || *p == '+'))
return false;
+ }
return true;
}
@@ -322,22 +334,24 @@ static int build_default_targets(struct bpm_build_upatch *u)
slash = strrchr(base, '/');
if (slash)
memmove(base, slash + 1, strlen(slash + 1) + 1);
- if (strlen(base) > 6 && !strcmp(base + strlen(base) - 6, ".bpf.c"))
+ if (strlen(base) > 6 && !strcmp(base + strlen(base) - 6, ".bpf.c")) {
base[strlen(base) - 6] = '\0';
- else if (strlen(base) > 6 && !strcmp(base + strlen(base) - 6, ".bpf.o"))
+ } else if (strlen(base) > 6 &&
+ !strcmp(base + strlen(base) - 6, ".bpf.o")) {
base[strlen(base) - 6] = '\0';
- else {
+ } else {
slash = strrchr(base, '.');
if (slash)
*slash = '\0';
}
if (!*base)
return -EINVAL;
- if (!u->load_target[0] && snprintf(u->load_target, sizeof(u->load_target),
- "upatches/%s.upatch", base) >= (int)sizeof(u->load_target))
+ if (!u->load_target[0] &&
+ snprintf(u->load_target, sizeof(u->load_target),
+ "upatches/%s.upatch", base) >= (int)sizeof(u->load_target))
return -ENAMETOOLONG;
if (!u->unload_target[0] && snprintf(u->unload_target,
- sizeof(u->unload_target), "upatches/%s.unload.upatch",
+ sizeof(u->unload_target), "upatches/%s.unload.upatch",
base) >= (int)sizeof(u->unload_target))
return -ENAMETOOLONG;
return 0;
@@ -455,11 +469,21 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)
char *dst = NULL;
size_t cap = 0;
- if (!strcmp(key, "source")) { dst = upatch->source; cap = sizeof(upatch->source); }
- else if (!strcmp(key, "type")) { dst = upatch->type; cap = sizeof(upatch->type); }
- else if (!strcmp(key, "load_target")) { dst = upatch->load_target; cap = sizeof(upatch->load_target); }
- else if (!strcmp(key, "unload_target")) { dst = upatch->unload_target; cap = sizeof(upatch->unload_target); }
- else return -EINVAL;
+ if (!strcmp(key, "source")) {
+ dst = upatch->source;
+ cap = sizeof(upatch->source);
+ } else if (!strcmp(key, "type")) {
+ dst = upatch->type;
+ cap = sizeof(upatch->type);
+ } else if (!strcmp(key, "load_target")) {
+ dst = upatch->load_target;
+ cap = sizeof(upatch->load_target);
+ } else if (!strcmp(key, "unload_target")) {
+ dst = upatch->unload_target;
+ cap = sizeof(upatch->unload_target);
+ } else {
+ return -EINVAL;
+ }
if (build_parse_string(value, dst, cap))
return -EINVAL;
} else if (tree_section && !strcmp(section, "upatches.tree")) {
@@ -468,10 +492,18 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)
size_t cap = 0;
/* Unknown tree keys are additive metadata for newer publishers. */
- if (!strcmp(key, "id")) { dst = t->id; cap = sizeof(t->id); }
- else if (!strcmp(key, "load_artifact")) { dst = t->load_artifact; cap = sizeof(t->load_artifact); }
- else if (!strcmp(key, "unload_artifact")) { dst = t->unload_artifact; cap = sizeof(t->unload_artifact); }
- else continue;
+ if (!strcmp(key, "id")) {
+ dst = t->id;
+ cap = sizeof(t->id);
+ } else if (!strcmp(key, "load_artifact")) {
+ dst = t->load_artifact;
+ cap = sizeof(t->load_artifact);
+ } else if (!strcmp(key, "unload_artifact")) {
+ dst = t->unload_artifact;
+ cap = sizeof(t->unload_artifact);
+ } else {
+ continue;
+ }
if (build_parse_string(value, dst, cap))
return -EINVAL;
} else if (tree_section && !strcmp(section, "upatches.tree.selector")) {
@@ -491,7 +523,7 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)
return -EINVAL;
}
if (*n || build_parse_string_array(value, dst,
- SHIRUDO_TREE_MAX_SELECTOR_VALUES, n))
+ SHIRUDO_TREE_MAX_SELECTOR_VALUES, n))
return -EINVAL;
} else if (tree_section && !strcmp(section, "upatches.tree.selector.kconfig")) {
if (build_parse_selector_kv(key, value, sel->kconfig,
@@ -575,10 +607,11 @@ void bpm_build_spec_free(struct bpm_build_spec *spec)
{
if (!spec)
return;
- for (size_t i = 0; i < spec->n_upatches; i++)
+ for (size_t i = 0; i < spec->n_upatches; i++) {
if (spec->upatches[i].tree.selector)
xfree(spec->upatches[i].tree.selector,
sizeof(*spec->upatches[i].tree.selector));
+ }
if (spec->build_file)
xfree(spec->build_file, spec->build_file_len + 1);
xfree(spec, sizeof(*spec));
@@ -638,9 +671,10 @@ static int build_add_target(char seen[][PATH_MAX], size_t *n, const char *target
if (!strcmp(target, "Beefile") || !strcmp(target, "README.md") ||
!strcmp(target, "cert.der") || !strcmp(target, "build-environment.json"))
return -EEXIST;
- for (size_t i = 0; i < *n; i++)
+ for (size_t i = 0; i < *n; i++) {
if (!strcmp(seen[i], target))
return -EEXIST;
+ }
if (*n >= BPM_BUILD_MAX_ENTRIES * 3)
return -E2BIG;
build_copy(seen[(*n)++], PATH_MAX, target);
@@ -657,7 +691,7 @@ static int build_validate(struct bpm_build_spec *spec)
for (size_t i = 0; i < spec->n_files; i++) {
if (build_add_target(seen, &n, spec->files[i].target) ||
build_resolve_source(spec, spec->files[i].source, resolved,
- sizeof(resolved), &st))
+ sizeof(resolved), &st))
return -EINVAL;
}
for (size_t i = 0; i < spec->n_upatches; i++) {
@@ -677,7 +711,7 @@ static int build_join(char *out, size_t cap, const char *dir, const char *name)
}
static int build_entry_name(char *out, size_t cap, const char *top,
- const char *entry)
+ const char *entry)
{
size_t top_len = strlen(top);
size_t entry_len = strlen(entry);
@@ -830,7 +864,7 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
}
static int build_environment(const struct bpm_build_spec *spec,
- const char *version, const char *fingerprint,
+ const char *version, const char *fingerprint,
unsigned char **out, size_t *out_len)
{
char *body = xmalloc(BPM_BUILD_MAX_JSON);
@@ -902,11 +936,11 @@ static int tar_write(struct bpm_tar *tar, const void *data, size_t len)
{
if (!len)
return 0;
- return gzwrite(tar->gz, data, (unsigned)len) == (int)len ? 0 : -EIO;
+ return gzwrite(tar->gz, data, (unsigned int)len) == (int)len ? 0 : -EIO;
}
static int tar_entry(struct bpm_tar *tar, const char *name, const void *data,
- size_t len, mode_t mode, char type)
+ size_t len, mode_t mode, char type)
{
unsigned char h[512] = {};
unsigned int sum = 0;
@@ -915,10 +949,10 @@ static int tar_entry(struct bpm_tar *tar, const char *name, const void *data,
if (strlen(name) >= 100 || (type == '0' && len > 077777777777ULL))
return -ENAMETOOLONG;
memcpy(h, name, strlen(name));
- snprintf((char *)h + 100, 8, "%07o", (unsigned)(mode & 07777));
+ snprintf((char *)h + 100, 8, "%07o", (unsigned int)(mode & 07777));
snprintf((char *)h + 108, 8, "%07o", 0u);
snprintf((char *)h + 116, 8, "%07o", 0u);
- snprintf((char *)h + 124, 12, "%011o", (unsigned)len);
+ snprintf((char *)h + 124, 12, "%011o", (unsigned int)len);
snprintf((char *)h + 136, 12, "%011o", 0u);
memset(h + 148, ' ', 8);
h[156] = (unsigned char)type;
@@ -967,7 +1001,7 @@ static int build_archive(const struct bpm_build_spec *spec, const char *version,
snprintf(output, sizeof(output), "%s/%s.bee", out_dir, top) >= (int)sizeof(output))
return -ENAMETOOLONG;
if (build_environment(spec, version, fingerprint, &environment,
- &environment_len))
+ &environment_len))
return -EIO;
if (build_read_file(cert_path, &cert, &cert_len, BPM_BUILD_MAX_FILE)) {
xfree(environment, BPM_BUILD_MAX_JSON);
@@ -986,14 +1020,14 @@ static int build_archive(const struct bpm_build_spec *spec, const char *version,
rc = build_entry_name(name, sizeof(name), top, "Beefile");
if (!rc)
rc = tar_entry(&tar, name, spec->build_file,
- spec->build_file_len, 0644, '0');
+ spec->build_file_len, 0644, '0');
}
for (size_t i = 0; !rc && i < spec->n_files; i++) {
char resolved[PATH_MAX];
struct stat st;
rc = build_resolve_source(spec, spec->files[i].source, resolved,
- sizeof(resolved), &st);
+ sizeof(resolved), &st);
if (!rc)
rc = build_entry_name(name, sizeof(name), top,
spec->files[i].target);
@@ -1037,7 +1071,7 @@ static int build_archive(const struct bpm_build_spec *spec, const char *version,
}
if (!rc) {
rc = build_entry_name(name, sizeof(name), top,
- "build-environment.json");
+ "build-environment.json");
if (!rc)
rc = tar_entry(&tar, name, environment, environment_len, 0644, '0');
}
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index d2108fc0..4816306f 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -91,7 +91,6 @@ static void sig_free(unsigned char *sig)
xfree(sig, BPM_SIGN_MAX);
}
-
static int index_entry_compare(const void *left, const void *right)
{
const struct bpm_index_entry *a = left, *b = right;
@@ -111,7 +110,7 @@ static int fetch_index(struct bpm_oci_client *c, const char *cert,
*n = 0;
rc = bpm_oci_url(c, BPM_INDEX_REPOSITORY, "manifests", BPM_INDEX_TAG,
- url, sizeof(url));
+ url, sizeof(url));
if (rc)
return rc;
rc = bpm_oci_get_memory(c, url, BPM_MANIFEST_MEDIA, &manifest);
@@ -142,7 +141,7 @@ static int fetch_index(struct bpm_oci_client *c, const char *cert,
goto out;
}
rc = bpm_oci_url(c, BPM_INDEX_REPOSITORY, "blobs", layers[i].digest,
- url, sizeof(url));
+ url, sizeof(url));
if (rc)
goto out;
rc = bpm_oci_get_blob(c, url, layers[i].media, dst);
@@ -270,13 +269,18 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
rc = sign_detached(body, e.len, key, cert, &sig, &sig_len);
if (rc)
goto out;
- if ((rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, empty_config,
- strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
- &config)) ||
- (rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, body, e.len,
- BPM_INDEX_MEDIA, &payload_layer)) ||
- (rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, sig, sig_len,
- BPM_INDEX_SIG_MEDIA, &sig_layer)))
+ rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &config);
+ if (rc)
+ goto out;
+ rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, body, e.len,
+ BPM_INDEX_MEDIA, &payload_layer);
+ if (rc)
+ goto out;
+ rc = bpm_oci_push_blob(c, BPM_INDEX_REPOSITORY, sig, sig_len,
+ BPM_INDEX_SIG_MEDIA, &sig_layer);
+ if (rc)
goto out;
manifest = xmalloc(BPM_MANIFEST_CAP);
if (!manifest) {
@@ -299,7 +303,7 @@ static int push_index(struct bpm_oci_client *c, const char *repository,
goto out;
}
rc = bpm_oci_put_manifest(c, BPM_INDEX_REPOSITORY, BPM_INDEX_TAG,
- (const unsigned char *)manifest, e.len, digest,
+ (const unsigned char *)manifest, e.len, digest,
sizeof(digest));
out:
if (manifest)
@@ -343,10 +347,12 @@ static int push_package(const char *package_path, const char *raw_repository,
&archive_len);
if (rc)
return rc;
- if ((rc = bpm_pkg_load_info(package_path, &info)))
+ rc = bpm_pkg_load_info(package_path, &info);
+ if (rc)
goto out;
- if ((rc = bpm_oci_parse_push_repo(raw_repository, &c, repository,
- sizeof(repository))))
+ rc = bpm_oci_parse_push_repo(raw_repository, &c, repository,
+ sizeof(repository));
+ if (rc)
goto out;
base = strrchr(package_path, '/');
base = base ? base + 1 : package_path;
@@ -356,11 +362,13 @@ static int push_package(const char *package_path, const char *raw_repository,
}
bpm_copy_string(package_title, sizeof(package_title), base);
- if ((rc = bpm_oci_push_blob(&c, repository, config_body,
- strlen(config_body), BPM_CONFIG_MEDIA, &config)))
+ rc = bpm_oci_push_blob(&c, repository, config_body, strlen(config_body),
+ BPM_CONFIG_MEDIA, &config);
+ if (rc)
goto out;
- if ((rc = bpm_oci_push_blob(&c, repository, archive, archive_len,
- BPM_PACKAGE_MEDIA, &layer)))
+ rc = bpm_oci_push_blob(&c, repository, archive, archive_len,
+ BPM_PACKAGE_MEDIA, &layer);
+ if (rc)
goto out;
manifest_body = xmalloc(BPM_MANIFEST_CAP);
@@ -410,11 +418,14 @@ static int push_package(const char *package_path, const char *raw_repository,
* Publish the package certificate as an OCI referrer so `bpm key add`
* can fetch it without downloading the package.
*/
- if ((rc = bpm_oci_push_blob(&c, repository, empty_config, strlen(empty_config),
- BPM_EMPTY_CONFIG_MEDIA, &key_config)))
+ rc = bpm_oci_push_blob(&c, repository, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &key_config);
+ if (rc)
goto out;
- if ((rc = bpm_oci_push_blob(&c, repository, info.cert, info.cert_len,
- BPM_PUBLIC_KEY_MEDIA, &key_layer)))
+ rc = bpm_oci_push_blob(&c, repository, info.cert, info.cert_len,
+ BPM_PUBLIC_KEY_MEDIA, &key_layer);
+ if (rc)
goto out;
subject = (struct bpm_descriptor){
.media = "application/vnd.oci.image.manifest.v1+json",
@@ -447,20 +458,24 @@ static int push_package(const char *package_path, const char *raw_repository,
}
key_manifest_len = e.len;
if (bpm_sha256_hex(key_manifest_body, key_manifest_len, hex,
- sizeof(hex)) ||
+ sizeof(hex)) ||
snprintf(key_digest, sizeof(key_digest), "sha256:%s", hex) >=
(int)sizeof(key_digest)) {
rc = -EINVAL;
goto out;
}
- if ((rc = bpm_oci_put_manifest(&c, repository, key_digest,
- (const unsigned char *)key_manifest_body,
- key_manifest_len, key_digest, sizeof(key_digest))))
- goto out;
- if (index_key && index_cert &&
- (rc = push_index(&c, repository, &info, package_digest, &layer,
- index_key, index_cert)))
+ rc = bpm_oci_put_manifest(&c, repository, key_digest,
+ (const unsigned char *)key_manifest_body,
+ key_manifest_len, key_digest,
+ sizeof(key_digest));
+ if (rc)
goto out;
+ if (index_key && index_cert) {
+ rc = push_index(&c, repository, &info, package_digest, &layer,
+ index_key, index_cert);
+ if (rc)
+ goto out;
+ }
rc = bpm_oci_put_manifest(&c, repository, info.version, manifest,
manifest_len, package_digest,
sizeof(package_digest));
@@ -556,10 +571,14 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
(int)sizeof(tag) || strlen(tag) > 128)
return -ENAMETOOLONG;
snprintf(title, sizeof(title), "%s.upatch", id);
- if ((rc = bpm_oci_push_blob(c, repository, body, len, BPM_UPATCH_MEDIA,
- &layer)) ||
- (rc = bpm_oci_push_blob(c, repository, empty_config, strlen(empty_config),
- BPM_EMPTY_CONFIG_MEDIA, &config)))
+ rc = bpm_oci_push_blob(c, repository, body, len, BPM_UPATCH_MEDIA,
+ &layer);
+ if (rc)
+ return rc;
+ rc = bpm_oci_push_blob(c, repository, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &config);
+ if (rc)
return rc;
manifest = xmalloc(BPM_MANIFEST_CAP);
if (!manifest)
@@ -580,7 +599,7 @@ static int tree_push_artifact(struct bpm_oci_client *c, const char *repository,
rc = e.err;
if (!rc)
rc = bpm_oci_put_manifest(c, repository, tag,
- (const unsigned char *)manifest, e.len,
+ (const unsigned char *)manifest, e.len,
out->manifest_digest,
sizeof(out->manifest_digest));
xfree(manifest, BPM_MANIFEST_CAP);
@@ -618,37 +637,38 @@ static int cmd_bpm_tree_append(int argc, char **argv)
for (int i = 2; i < argc; i++) {
const char *a = argv[i];
- if (!strcmp(a, "--keys-dir") && i + 1 < argc)
+ if (!strcmp(a, "--keys-dir") && i + 1 < argc) {
keys_dir_arg = argv[++i];
- else if (!strncmp(a, "--keys-dir=", 11))
+ } else if (!strncmp(a, "--keys-dir=", 11)) {
keys_dir_arg = a + 11;
- else if (!strcmp(a, "--key") && i + 1 < argc)
+ } else if (!strcmp(a, "--key") && i + 1 < argc) {
key = argv[++i];
- else if (!strncmp(a, "--key=", 6))
+ } else if (!strncmp(a, "--key=", 6)) {
key = a + 6;
- else if (!strcmp(a, "--cert") && i + 1 < argc)
+ } else if (!strcmp(a, "--cert") && i + 1 < argc) {
cert = argv[++i];
- else if (!strncmp(a, "--cert=", 7))
+ } else if (!strncmp(a, "--cert=", 7)) {
cert = a + 7;
- else if (!strcmp(a, "--tree-id") && i + 1 < argc)
+ } else if (!strcmp(a, "--tree-id") && i + 1 < argc) {
tree_id = argv[++i];
- else if (!strncmp(a, "--tree-id=", 10))
+ } else if (!strncmp(a, "--tree-id=", 10)) {
tree_id = a + 10;
- else if (!strcmp(a, "--reference") && i + 1 < argc)
+ } else if (!strcmp(a, "--reference") && i + 1 < argc) {
reference = argv[++i];
- else if (!strncmp(a, "--reference=", 12))
+ } else if (!strncmp(a, "--reference=", 12)) {
reference = a + 12;
- else if (!strcmp(a, "--op") && i + 1 < argc)
+ } else if (!strcmp(a, "--op") && i + 1 < argc) {
operation = argv[++i];
- else if (!strncmp(a, "--op=", 5))
+ } else if (!strncmp(a, "--op=", 5)) {
operation = a + 5;
- else if (a[0] == '-' || (package && raw_repository)) {
+ } else if (a[0] == '-' || (package && raw_repository)) {
tree_append_usage();
return -EINVAL;
- } else if (!package)
+ } else if (!package) {
package = a;
- else
+ } else {
raw_repository = a;
+ }
}
if (!package || !raw_repository) {
tree_append_usage();
@@ -709,7 +729,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
goto out;
}
rc = bpm_tree_fetch_publication(&c, repository, reference, cert, &pub,
- parent, sizeof(parent));
+ parent, sizeof(parent));
if (rc == -ENOENT) {
pub = (struct shirudo_tree_publication){ .schema = 2,
.generation = 1 };
@@ -785,12 +805,18 @@ static int cmd_bpm_tree_append(int argc, char **argv)
rc = sign_detached(payload, payload_len, key, cert, &sig, &sig_len);
if (rc)
goto out;
- if ((rc = bpm_oci_push_blob(&c, repository, empty_config, strlen(empty_config),
- BPM_EMPTY_CONFIG_MEDIA, &config)) ||
- (rc = bpm_oci_push_blob(&c, repository, payload, payload_len,
- BPM_TREE_MEDIA, &payload_layer)) ||
- (rc = bpm_oci_push_blob(&c, repository, sig, sig_len, BPM_TREE_SIG_MEDIA,
- &sig_layer)))
+ rc = bpm_oci_push_blob(&c, repository, empty_config,
+ strlen(empty_config), BPM_EMPTY_CONFIG_MEDIA,
+ &config);
+ if (rc)
+ goto out;
+ rc = bpm_oci_push_blob(&c, repository, payload, payload_len,
+ BPM_TREE_MEDIA, &payload_layer);
+ if (rc)
+ goto out;
+ rc = bpm_oci_push_blob(&c, repository, sig, sig_len, BPM_TREE_SIG_MEDIA,
+ &sig_layer);
+ if (rc)
goto out;
manifest = xmalloc(BPM_MANIFEST_CAP);
if (!manifest) {
@@ -811,7 +837,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
rc = e.err;
if (!rc)
rc = bpm_oci_put_manifest(&c, repository, reference,
- (const unsigned char *)manifest, e.len,
+ (const unsigned char *)manifest, e.len,
digest, sizeof(digest));
if (!rc)
printf("oci://%s/%s:%s %s\n", c.registry, repository, reference,
@@ -863,25 +889,26 @@ int shirudo_build_bpm_push(int argc, char **argv)
for (int i = 1; i < argc; i++) {
const char *a = argv[i];
- if (!strcmp(a, "--keys-dir") && i + 1 < argc)
+ if (!strcmp(a, "--keys-dir") && i + 1 < argc) {
keys_dir_arg = argv[++i];
- else if (!strncmp(a, "--keys-dir=", 11))
+ } else if (!strncmp(a, "--keys-dir=", 11)) {
keys_dir_arg = a + 11;
- else if (!strcmp(a, "--index-cert") && i + 1 < argc)
+ } else if (!strcmp(a, "--index-cert") && i + 1 < argc) {
index_cert = argv[++i];
- else if (!strncmp(a, "--index-cert=", 13))
+ } else if (!strncmp(a, "--index-cert=", 13)) {
index_cert = a + 13;
- else if (!strcmp(a, "--index-key") && i + 1 < argc)
+ } else if (!strcmp(a, "--index-key") && i + 1 < argc) {
index_key = argv[++i];
- else if (!strncmp(a, "--index-key=", 12))
+ } else if (!strncmp(a, "--index-key=", 12)) {
index_key = a + 12;
- else if (a[0] == '-' || (package && repository)) {
+ } else if (a[0] == '-' || (package && repository)) {
bpm_push_usage();
return 2;
- } else if (!package)
+ } else if (!package) {
package = a;
- else
+ } else {
repository = a;
+ }
}
if (!package || !repository) {
bpm_push_usage();
diff --git a/tools/shirudo-build/compile.c b/tools/shirudo-build/compile.c
index f02083ec..dd8f7403 100644
--- a/tools/shirudo-build/compile.c
+++ b/tools/shirudo-build/compile.c
@@ -160,9 +160,9 @@ int shirudo_build_compile(const char *source, const char *output,
if (WIFEXITED(status)) {
int es = WEXITSTATUS(status);
- if (es == 0)
+ if (es == 0) {
rc = 0;
- else {
+ } else {
pr_err("clang exited with status %d", es);
rc = -EIO;
}
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index a28e6567..4fce0bb9 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -106,7 +106,6 @@ static void pack_header(struct shirudo_upatch_header *h,
h->reserved1 = 0;
}
-
static bool unsupported_kprobe_section(const char *sec)
{
if (sec && sec[0] == '?')
@@ -328,7 +327,7 @@ static bool object_has_map(struct bpf_object *obj, const char *want)
static bool fixed_cstr_nonempty(const char *s, size_t n)
{
- return n && s[0] && memchr(s, '\0', n) != NULL;
+ return n && s[0] && memchr(s, '\0', n);
}
static void copy_fixed_cstr(char *dst, size_t dst_sz,
@@ -875,20 +874,22 @@ static int build_prog_metadata(struct bpf_object *obj, uint32_t nr_progs,
&uprobe_targets[nr_uprobe_targets];
err = split_uprobe_target(target, &ut->path,
- &ut->path_len,
- md->progs[i].target,
- sizeof(md->progs[i].target));
+ &ut->path_len,
+ md->progs[i].target,
+ sizeof(md->progs[i].target));
if (err) {
if (err == -EOPNOTSUPP)
- pr_err("invalid uprobe.multi section '%s': ',' and '|' alternation are unsupported; use one '*'/'?' glob", sec);
+ pr_err("invalid uprobe.multi section '%s': ',' and '|' alternation are unsupported; use one '*'/'?' glob",
+ sec);
else
- pr_err("invalid uprobe.multi section '%s'; expected uprobe.multi//absolute/path:function_glob", sec);
+ pr_err("invalid uprobe.multi section '%s'; expected uprobe.multi//absolute/path:function_glob",
+ sec);
goto err_free;
}
ut->prog_idx = i;
nr_uprobe_targets++;
err = shirudo_elf_target_resolve(ut->path,
- md->progs[i].target, &ut->elf);
+ md->progs[i].target, &ut->elf);
if (err) {
if (err == -ENOENT)
pr_err("uprobe.multi pattern '%s' matched no functions in %s (or the ELF has no GNU build ID)",
@@ -1034,15 +1035,17 @@ static int set_target_attach_types(struct bpf_object *obj)
static int register_target_attach_types(int handler_ids[2])
{
- handler_ids[0] = libbpf_register_prog_handler(
- "cgroup_skb/ingress", BPF_PROG_TYPE_CGROUP_SKB,
- BPF_CGROUP_INET_INGRESS, NULL);
+ handler_ids[0] = libbpf_register_prog_handler("cgroup_skb/ingress",
+ BPF_PROG_TYPE_CGROUP_SKB,
+ BPF_CGROUP_INET_INGRESS,
+ NULL);
if (handler_ids[0] < 0)
return handler_ids[0];
- handler_ids[1] = libbpf_register_prog_handler(
- "cgroup_skb/egress", BPF_PROG_TYPE_CGROUP_SKB,
- BPF_CGROUP_INET_EGRESS, NULL);
+ handler_ids[1] = libbpf_register_prog_handler("cgroup_skb/egress",
+ BPF_PROG_TYPE_CGROUP_SKB,
+ BPF_CGROUP_INET_EGRESS,
+ NULL);
if (handler_ids[1] < 0) {
libbpf_unregister_prog_handler(handler_ids[0]);
handler_ids[0] = -1;
diff --git a/tools/shirudo-build/shirudo-build.c b/tools/shirudo-build/shirudo-build.c
index bd047e01..f63b8c97 100644
--- a/tools/shirudo-build/shirudo-build.c
+++ b/tools/shirudo-build/shirudo-build.c
@@ -30,7 +30,6 @@
#define SHIRUDO_VMLINUX_PATH "/usr/local/share/shirudo/vmlinux.h"
#endif
-
static void usage(FILE *fp)
{
fprintf(fp,
@@ -292,20 +291,20 @@ int main(int argc, char **argv)
keys_dir,
SHIRUDO_SIGNING_KEY_FILE);
if (rc) {
- pr_err("invalid keys dir %s: %s",
- keys_dir, strerror(-rc));
- return 2;
- }
+ pr_err("invalid keys dir %s: %s",
+ keys_dir, strerror(-rc));
+ return 2;
+ }
pkey = pkey_path;
}
if (!cert_explicit) {
rc = shirudo_key_path(cert_path, sizeof(cert_path),
keys_dir, SHIRUDO_CERT_FILE);
if (rc) {
- pr_err("invalid keys dir %s: %s",
- keys_dir, strerror(-rc));
- return 2;
- }
+ pr_err("invalid keys dir %s: %s",
+ keys_dir, strerror(-rc));
+ return 2;
+ }
cert = cert_path;
}
}