Skip to content

eBPF-based security platform

treewide: state what the code relies on where the analyzer cannot see it

Daniel Borkmann63195f92e331
diff --git a/builtin-status.c b/builtin-status.c
index 5b582259..66214165 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -986,8 +986,6 @@ static void keyring_emit_json(struct json_emit *e, const char *key,
json_arr_open(e, "certs");
for (i = 0; i < k->n_certs; i++) {
const struct status_cert *c = &k->certs[i];
- const struct keyring_link *l = c->link >= 0 ?
- &k->links[c->link] : NULL;
char sha_hex[65], fp_hex[65];
hex_encode(c->sha256, 32, sha_hex);
@@ -1005,7 +1003,9 @@ static void keyring_emit_json(struct json_emit *e, const char *key,
json_kv_string(e, "algorithm", c->algorithm);
json_kv_string(e, "not_before", c->not_before);
}
- if (l) {
+ if (c->link >= 0) {
+ const struct keyring_link *l = &k->links[c->link];
+
json_kv_int(e, "key_serial", l->serial);
json_kv_string(e, "key_description", l->description);
json_kv_bool(e, "frozen", k->state[c->link].frozen);
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 987190e9..d9595ca8 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1111,10 +1111,12 @@ static int prepare_uprobe_targets(struct prog_spec *specs,
return -E2BIG;
}
fd = open(proc_path, O_RDONLY | O_CLOEXEC);
- ret = fd < 0 ? -errno : 0;
- close(path_fd);
- if (ret)
+ if (fd < 0) {
+ ret = -errno;
+ close(path_fd);
return ret;
+ }
+ close(path_fd);
if (fstat(fd, &opened_stat) != 0) {
ret = -errno;
close(fd);
diff --git a/util/bpm_oci.c b/util/bpm_oci.c
index 2180f713..eb0088f8 100644
--- a/util/bpm_oci.c
+++ b/util/bpm_oci.c
@@ -1042,7 +1042,7 @@ int bpm_oci_parse_pull_ref(const char *raw, struct bpm_oci_client *c,
{
const char *p, *slash, *colon, *last_slash;
char endpoint[BPM_MAX_ENDPOINT];
- char normalized[PATH_MAX];
+ char normalized[PATH_MAX] = {};
if (!raw || strlen(raw) >= sizeof(normalized))
return -EINVAL;
@@ -1091,7 +1091,7 @@ int bpm_oci_parse_pull_ref(const char *raw, struct bpm_oci_client *c,
int bpm_oci_parse_push_repo(const char *raw, struct bpm_oci_client *c,
char *repository, size_t repository_sz)
{
- char normalized[PATH_MAX], endpoint[BPM_MAX_ENDPOINT];
+ char normalized[PATH_MAX] = {}, endpoint[BPM_MAX_ENDPOINT];
const char *p, *slash;
if (!raw || strlen(raw) >= sizeof(normalized))
diff --git a/util/config_update.c b/util/config_update.c
index fea813ef..04a26187 100644
--- a/util/config_update.c
+++ b/util/config_update.c
@@ -686,7 +686,7 @@ int config_update_staged(struct config_update *update,
__u32 reset, __u32 restart,
struct config_update_target *target)
{
- struct config_update_record staged;
+ struct config_update_record staged = {};
int ret;
if (!previous || !target)
@@ -756,7 +756,7 @@ int config_update_boot(struct config_update *update,
__u32 pcr)
{
struct config_update_record previous = {}, last;
- struct config_update_target staged;
+ struct config_update_target staged = {};
__u32 reset, restart;
int ret;
diff --git a/util/io.c b/util/io.c
index a627faee..63bd2bee 100644
--- a/util/io.c
+++ b/util/io.c
@@ -93,7 +93,7 @@ static int last_line_end(int fd, off_t size, off_t *end)
int append_line(int fd, const char *path, const char *line, size_t len)
{
struct stat st;
- off_t end;
+ off_t end = 0;
char *buf;
int ret;
diff --git a/util/seal.c b/util/seal.c
index 93fe78b0..bb28ae1c 100644
--- a/util/seal.c
+++ b/util/seal.c
@@ -57,7 +57,7 @@ static int open_parent(int fd, struct stat *st)
*/
int seal_mark_ancestors(const char *root)
{
- struct stat st, cur, up;
+ struct stat st = {}, cur = {}, up = {};
int fd, parent, ret;
fd = open(root, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
diff --git a/util/sysinfo.c b/util/sysinfo.c
index c3489d71..02415838 100644
--- a/util/sysinfo.c
+++ b/util/sysinfo.c
@@ -436,7 +436,7 @@ void sysinfo_image_read_at(const char *os_release,
const char *os_release_fallback,
const char *cmdline, struct sysinfo_image *img)
{
- char line[CMDLINE_SIZE_MAX];
+ char line[CMDLINE_SIZE_MAX] = {};
size_t len;
char *text;
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index f78a1f91..1eb4d4b3 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -1450,23 +1450,22 @@ struct snapshot_writer {
* In memory: a file under TMPDIR, which root sets, could be created in a
* sealed directory, labeled.
*/
-static int snapshot_temp_file(FILE **out)
+/* As fopen(): the stream, or NULL with errno set. */
+static FILE *snapshot_temp_file(void)
{
FILE *file;
- int fd;
+ int fd, err;
fd = memfd_create("shirudo-map-snapshot", MFD_CLOEXEC);
if (fd < 0)
- return -errno;
+ return NULL;
file = fdopen(fd, "w+b");
if (!file) {
- int ret = -errno;
-
+ err = errno;
close(fd);
- return ret;
+ errno = err;
}
- *out = file;
- return 0;
+ return file;
}
static int snapshot_write_compressed(struct snapshot_writer *w,
@@ -1606,8 +1605,9 @@ static int build_s3_snapshot(const char *decoder_path,
&decoded_len);
if (ret)
return ret;
- ret = snapshot_temp_file(&snapshot->file);
- if (ret) {
+ snapshot->file = snapshot_temp_file();
+ if (!snapshot->file) {
+ ret = -errno;
xfree(decoded, decoded_len + 1);
return ret;
}