eBPF-based security platform
treewide: drop comparisons whose outcome is already decided
Daniel Borkmann297e5463cd59
diff --git a/builtin-genkey.c b/builtin-genkey.cindex 4e26475f..d657c7c4 100644--- a/builtin-genkey.c+++ b/builtin-genkey.c@@ -319,8 +319,7 @@ static int write_cert_der(X509 *c, const char *path)ret = 0;out:BIO_free(bio);- if (fd >= 0)- close(fd);+ close(fd);if (ret != 0)unlink(path);return ret;diff --git a/testing/helper/test-keepalive-quote.c b/testing/helper/test-keepalive-quote.cindex ee91847e..2d208f9e 100644--- a/testing/helper/test-keepalive-quote.c+++ b/testing/helper/test-keepalive-quote.c@@ -38,15 +38,18 @@ static int quote_values(char *quote, const char *values[QUOTE_FIELDS])if (strncmp(field, keys[i], n))return -EINVAL;values[i] = field + n;- end = strchr(field + n, ';');- if (i + 1 == QUOTE_FIELDS)- return end ? -EINVAL : 0;- if (!end)- return -EINVAL;- *end = '\0';- field = end + 1;+ end = strchr(values[i], ';');+ if (i + 1 == QUOTE_FIELDS) {+ if (end)+ return -EINVAL;+ } else {+ if (!end)+ return -EINVAL;+ *end = '\0';+ field = end + 1;+ }}- return -EINVAL;+ return 0;}static int print_row(const char *path, const char *body, size_t len)diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.cindex ef5d942b..91c171a5 100644--- a/tools/shirudo-build/package.c+++ b/tools/shirudo-build/package.c@@ -363,8 +363,7 @@ int build_package_patch_rodata(const char *input, const char *output,char modified[] = "/tmp/shirudo-rodata-XXXXXX";__u8 *candidate = NULL;bool created = false;- int fd = -1;- int ret;+ int fd, ret;if (!input || !output || !symbol || !value || !value_len ||!strcmp(input, output))@@ -405,7 +404,6 @@ int build_package_patch_rodata(const char *input, const char *output,ret = -errno;if (close(fd) && !ret)ret = -errno;- fd = -1;if (ret)goto out;allowed.offset = range.offset;@@ -414,8 +412,6 @@ int build_package_patch_rodata(const char *input, const char *output,symbols, ARRAY_SIZE(symbols), pkey_path,cert_path);out:- if (fd >= 0)- close(fd);if (created)unlink(modified);xfree(candidate, src.map_size);diff --git a/util/elf_target.c b/util/elf_target.cindex 59025176..99987a4d 100644--- a/util/elf_target.c+++ b/util/elf_target.c@@ -141,6 +141,9 @@ int elf_build_id_fd(int fd,return err;}+/* The resolved offsets are counted in a __u32. */+BUILD_BUG_ON(UPATCH_UPROBE_OFFSETS_MAX > UINT32_MAX);+int elf_target_resolve(const char *path, const char *pattern,struct elf_target *out){@@ -148,7 +151,7 @@ int elf_target_resolve(const char *path, const char *pattern,unsigned long *resolved_offsets = NULL;__u32 i, unique;size_t nr_resolved = 0;- int fd = -1, err;+ int fd, err;if (!path || path[0] != '/' || !pattern || !pattern[0] || !out)return -EINVAL;@@ -180,8 +183,7 @@ int elf_target_resolve(const char *path, const char *pattern,err = -ENOENT;goto out;}- if (nr_resolved > UPATCH_UPROBE_OFFSETS_MAX ||- nr_resolved > UINT32_MAX) {+ if (nr_resolved > UPATCH_UPROBE_OFFSETS_MAX) {err = -E2BIG;goto out;}@@ -207,8 +209,7 @@ int elf_target_resolve(const char *path, const char *pattern,out:if (elf)elf_end(elf);- if (fd >= 0)- close(fd);+ close(fd);libc_free(resolved_offsets);if (err)elf_target_free(out);diff --git a/util/upatch_maps.c b/util/upatch_maps.cindex 271b9668..bb7c143d 100644--- a/util/upatch_maps.c+++ b/util/upatch_maps.c@@ -1064,8 +1064,7 @@ out:close(serial_fd);if (lock_fd >= 0)close(lock_fd);- if (prog_fd >= 0)- close(prog_fd);+ close(prog_fd);return ret;}