Skip to content

eBPF-based security platform

treewide: search with span_find() and str_contains(), not strstr()

Daniel Borkmann4e295a9571a3
diff --git a/builtin-bpm.c b/builtin-bpm.c
index 64adb6d7..f2a7081c 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -415,7 +415,7 @@ static int load_source(const char *name, struct bpm_source *s)
if (str_has_prefix(s->key_file, "/etc/shirudo/bpm/keys/"))
memmove(s->key_file, s->key_file + 1,
strlen(s->key_file));
- if (s->key_file[0] == '/' || strstr(s->key_file, ".."))
+ if (s->key_file[0] == '/' || str_contains(s->key_file, ".."))
return -EINVAL;
}
return 0;
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 5823159c..bce35902 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1017,13 +1017,13 @@ static int cgroup_skb_attach_type_from_name(const char *name,
{
if (!name || !name[0])
return -EINVAL;
- if (strstr(name, "egress") || strstr(name, "query") ||
- strstr(name, "send")) {
+ if (str_contains(name, "egress") || str_contains(name, "query") ||
+ str_contains(name, "send")) {
*attach_type = BPF_CGROUP_INET_EGRESS;
return 0;
}
- if (strstr(name, "ingress") || strstr(name, "response") ||
- strstr(name, "recv") || strstr(name, "receive")) {
+ if (str_contains(name, "ingress") || str_contains(name, "response") ||
+ str_contains(name, "recv") || str_contains(name, "receive")) {
*attach_type = BPF_CGROUP_INET_INGRESS;
return 0;
}
diff --git a/testing/helper/test-tpm-session.c b/testing/helper/test-tpm-session.c
index bc0c5f00..6f5676c8 100644
--- a/testing/helper/test-tpm-session.c
+++ b/testing/helper/test-tpm-session.c
@@ -239,7 +239,7 @@ static int evidence_begins(const char *array)
NULL, NULL, &doc, &len, &cap);
if (ret)
return ret;
- ret = strstr(doc, array) ? 0 : -EBADMSG;
+ ret = str_contains(doc, array) ? 0 : -EBADMSG;
xfree(doc, cap);
return ret;
}
diff --git a/testing/helper/test-upatch-serializer-pages.c b/testing/helper/test-upatch-serializer-pages.c
index 26cd728f..6ba279e0 100644
--- a/testing/helper/test-upatch-serializer-pages.c
+++ b/testing/helper/test-upatch-serializer-pages.c
@@ -26,7 +26,8 @@ static int fail(const char *msg)
static int has(const char *haystack, const char *needle)
{
- return strstr(haystack, needle) != NULL;
+ return memmem(haystack, strlen(haystack), needle, strlen(needle)) !=
+ NULL;
}
static int check_abi_and_nonce(void)
diff --git a/testing/proofs/cbmc/bpm-oci-token.c b/testing/proofs/cbmc/bpm-oci-token.c
index 962920b4..4614924d 100644
--- a/testing/proofs/cbmc/bpm-oci-token.c
+++ b/testing/proofs/cbmc/bpm-oci-token.c
@@ -74,8 +74,8 @@ static void answer_text(void)
__CPROVER_assert(header_safe(out),
"no blank, control, quote or backslash in the token");
__CPROVER_assert(quoted_in(body, len, out) &&
- (strstr(body, "\"token\"") ||
- strstr(body, "\"access_token\"")),
+ (str_contains(body, "\"token\"") ||
+ str_contains(body, "\"access_token\"")),
"a quoted value of an answer naming a token");
}
diff --git a/testing/proofs/cbmc/proof.h b/testing/proofs/cbmc/proof.h
index 3719c90e..8ecdb528 100644
--- a/testing/proofs/cbmc/proof.h
+++ b/testing/proofs/cbmc/proof.h
@@ -25,15 +25,14 @@
#include <shirudo/types.h>
/*
- * glibc 2.43 makes these const-preserving _Generic macros under C23,
+ * glibc 2.43 makes this a const-preserving _Generic macro under C23,
* which a definition of the function cannot be spelled through.
*/
#undef memchr
-#undef strstr
/*
- * CBMC models neither strnlen(), memchr(), memmem(), strstr() nor
- * vsnprintf(), and a function without a body returns anything.
+ * CBMC models neither strnlen(), memchr(), memmem() nor vsnprintf(), and
+ * a function without a body returns anything.
*/
size_t strnlen(const char *s, size_t max)
{
@@ -90,18 +89,6 @@ void *memmem(const void *hay, size_t hay_len, const void *needle,
return NULL;
}
-char *strstr(const char *s, const char *needle)
-{
- size_t n = strlen(needle);
-
- for (;; s++) {
- if (!strncmp(s, needle, n))
- return (char *)s;
- if (!*s)
- return NULL;
- }
-}
-
static size_t format_char(char *buf, size_t size, size_t n, char c)
{
if (n + 1 < size)
diff --git a/testing/unit/attest.c b/testing/unit/attest.c
index d047d64a..7a8b932e 100644
--- a/testing/unit/attest.c
+++ b/testing/unit/attest.c
@@ -140,9 +140,11 @@ static void record_without_digest_is_refused(void)
full = read_evidence(&len);
ASSERT_TRUE(len < sizeof(doc));
memcpy(doc, full, len);
- load = strstr(doc, "\"type\":\"upatch_load\"");
+ load = span_find(doc, len, "\"type\":\"upatch_load\"");
ASSERT_TRUE(load);
- for (at = doc; (at = strstr(at, key)) && at < load; at++)
+ for (at = doc;
+ (at = span_find(at, len - (size_t)(at - doc), key)) && at < load;
+ at++)
digest = at;
ASSERT_TRUE(digest);
cut = sizeof(key) - 1 + 64 + 2;
diff --git a/testing/unit/bpm_tree.c b/testing/unit/bpm_tree.c
index cf8733d8..87b1dade 100644
--- a/testing/unit/bpm_tree.c
+++ b/testing/unit/bpm_tree.c
@@ -131,8 +131,8 @@ static void publication_carries_keys_outside_the_digest(void)
pub.head_seq = 1;
ASSERT_EQ(tree_emit_publication(&pub, &extra, &doc, &len), 0);
EXPECT_GT(len, 64 * 200);
- fixes = strstr(doc, "},\"fixes\":[\"AAAA");
- digest = strstr(doc, "\"],\"operation_digest\":");
+ fixes = span_find(doc, len, "},\"fixes\":[\"AAAA");
+ digest = span_find(doc, len, "\"],\"operation_digest\":");
EXPECT_TRUE(fixes && digest && fixes < digest);
ASSERT_EQ(tree_parse(doc, len, &back), 0);
ASSERT_EQ(back.n_operations, 1);
@@ -178,7 +178,7 @@ static void publication_reads_past_malformed_fixes(void)
ASSERT_EQ(tree_publication_append(&pub, op), 0);
pub.head_seq = 1;
ASSERT_EQ(tree_emit_publication(&pub, &extra, &doc, &len), 0);
- EXPECT_TRUE(strstr(doc, "\"fixes\":{\"n\":[null,\"\\u0007\"]}"));
+ EXPECT_TRUE(str_contains(doc, "\"fixes\":{\"n\":[null,\"\\u0007\"]}"));
ASSERT_EQ(tree_parse(doc, len, &back), 0);
EXPECT_EQ(tree_publication_check(&back), 0);
ASSERT_EQ(back.n_operations, 1);
@@ -210,7 +210,7 @@ static void segment_reads_back(void)
ASSERT_EQ(tree_operation_digest(op, op->operation_digest), 0);
ASSERT_EQ(tree_publication_append(&pub, op), 0);
ASSERT_EQ(tree_emit_publication(&pub, NULL, &doc, &len), 0);
- EXPECT_TRUE(strstr(doc, "\"base\":{\"seq\":2,"
+ EXPECT_TRUE(str_contains(doc, "\"base\":{\"seq\":2,"
"\"segment_manifest_digest\":\"" SEALED "\","
"\"history_root\":\"" ROOT "\"},"));
ASSERT_EQ(tree_parse(doc, len, &back), 0);
@@ -224,7 +224,7 @@ static void segment_reads_back(void)
tree_publication_free(&back);
pub.history_root[0] = '\0';
ASSERT_EQ(tree_emit_publication(&pub, NULL, &doc, &len), 0);
- EXPECT_FALSE(strstr(doc, "history_root"));
+ EXPECT_FALSE(str_contains(doc, "history_root"));
xfree(doc, len);
tree_publication_free(&pub);
tree_selector_free(&op->selector);
diff --git a/testing/unit/chain.c b/testing/unit/chain.c
index e6e83f78..f52b6b6d 100644
--- a/testing/unit/chain.c
+++ b/testing/unit/chain.c
@@ -7,6 +7,8 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <shirudo/string.h>
+
#include "chain.h"
#include "crypto.h"
#include "unit.h"
@@ -116,14 +118,15 @@ static void chain_log_anchor_appends_a_systemd_record(void)
rec = strchr(buf + 1, 0x1e);
ASSERT_TRUE(rec);
EXPECT_EQ(rec[-1], '\n');
- EXPECT_TRUE(strstr(buf, "{\"pcr\":9,\"digests\":[{\"hashAlg\":"
- "\"sha256\",\"digest\":\"") == buf + 1);
- EXPECT_TRUE(strstr(buf, hex));
- EXPECT_TRUE(strstr(buf, "\"content_type\":\"systemd\",\"content\":"
- "{\"string\":\"nvpcr-init:shirudo:0x1818e00:"
- "000b01\",\"bootId\":\""));
- EXPECT_TRUE(strstr(buf, "\"eventType\":\"nvpcr-init\"}}\n"));
- boot = strstr(buf, "\"bootId\":\"");
+ EXPECT_TRUE(span_find(buf, strlen(buf),
+ "{\"pcr\":9,\"digests\":[{\"hashAlg\":"
+ "\"sha256\",\"digest\":\"") == buf + 1);
+ EXPECT_TRUE(str_contains(buf, hex));
+ EXPECT_TRUE(str_contains(buf, "\"content_type\":\"systemd\",\"content\":"
+ "{\"string\":\"nvpcr-init:shirudo:0x1818e00:"
+ "000b01\",\"bootId\":\""));
+ EXPECT_TRUE(str_contains(buf, "\"eventType\":\"nvpcr-init\"}}\n"));
+ boot = span_find(buf, strlen(buf), "\"bootId\":\"");
ASSERT_TRUE(boot);
EXPECT_TRUE(hex_is_lower(boot + 10, 32));
EXPECT_EQ(boot[42], '"');
diff --git a/testing/unit/conditions.c b/testing/unit/conditions.c
index d2cde623..41808494 100644
--- a/testing/unit/conditions.c
+++ b/testing/unit/conditions.c
@@ -4,6 +4,8 @@
#include <errno.h>
#include <string.h>
+#include <shirudo/string.h>
+
#include "conditions.h"
#include "unit.h"
@@ -39,8 +41,8 @@ static void changed_xdp_archive_is_tampered(void)
row = upatches_measured(&in, c);
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "ALERT");
- EXPECT_TRUE(strstr(row->detail, "1 XDP archives differ"));
- EXPECT_TRUE(strstr(row->detail, "fix"));
+ EXPECT_TRUE(str_contains(row->detail, "1 XDP archives differ"));
+ EXPECT_TRUE(str_contains(row->detail, "fix"));
EXPECT_STREQ(status_verdict(&in), "tampered");
}
@@ -75,7 +77,7 @@ static void a_lost_link_is_tampered(void)
row = upatches_measured(&in, c);
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "ALERT");
- EXPECT_TRUE(strstr(row->detail, "missing a link or their archive: fix"));
+ EXPECT_TRUE(str_contains(row->detail, "missing a link or their archive: fix"));
EXPECT_STREQ(status_verdict(&in), "tampered");
}
@@ -94,10 +96,10 @@ static void records_the_register_does_not_vouch_for_are_tampered(void)
row = upatches_measured(&in, c);
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "ALERT");
- EXPECT_TRUE(strstr(row->detail, "do not fold to the measurement register"));
+ EXPECT_TRUE(str_contains(row->detail, "do not fold to the measurement register"));
EXPECT_STREQ(status_verdict(&in), "tampered");
status_reason(&in, reason, sizeof(reason));
- EXPECT_TRUE(strstr(reason, "do not fold to the measurement register"));
+ EXPECT_TRUE(str_contains(reason, "do not fold to the measurement register"));
}
static void a_check_that_could_not_run_warns(void)
@@ -114,7 +116,7 @@ static void a_check_that_could_not_run_warns(void)
row = upatches_measured(&in, c);
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "WARN");
- EXPECT_TRUE(strstr(row->detail, "not checked"));
+ EXPECT_TRUE(str_contains(row->detail, "not checked"));
EXPECT_TRUE(strcmp(status_verdict(&in), "tampered"));
}
@@ -152,10 +154,10 @@ static void an_uncovered_device_degrades(void)
row = condition_of(&in, c, "XdpCovered");
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "WARN");
- EXPECT_TRUE(strstr(row->detail, "fw on eth1 (no multi-buffer XDP)"));
+ EXPECT_TRUE(str_contains(row->detail, "fw on eth1 (no multi-buffer XDP)"));
EXPECT_STREQ(status_verdict(&in), "degraded");
status_reason(&in, reason, sizeof(reason));
- EXPECT_TRUE(strstr(reason, "XDP upatch selects"));
+ EXPECT_TRUE(str_contains(reason, "XDP upatch selects"));
}
static void unchecked_coverage_warns_without_degrading(void)
@@ -174,7 +176,7 @@ static void unchecked_coverage_warns_without_degrading(void)
row = condition_of(&in, c, "XdpCovered");
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "WARN");
- EXPECT_TRUE(strstr(row->detail, "not checked"));
+ EXPECT_TRUE(str_contains(row->detail, "not checked"));
EXPECT_STREQ(status_verdict(&in), "ok");
in.xdp_coverage_rc = -EXDEV;
row = condition_of(&in, c, "XdpCovered");
@@ -224,7 +226,7 @@ static void a_long_list_is_cut_not_dropped(void)
ASSERT_TRUE(row);
len = strlen(row->detail);
EXPECT_EQ(len, sizeof(row->detail) - 1);
- EXPECT_TRUE(strstr(row->detail, "fw on eth1"));
+ EXPECT_TRUE(str_contains(row->detail, "fw on eth1"));
EXPECT_STREQ(row->detail + len - 3, "...");
}
diff --git a/testing/unit/json.c b/testing/unit/json.c
index 6f53fa4e..6608052a 100644
--- a/testing/unit/json.c
+++ b/testing/unit/json.c
@@ -703,7 +703,7 @@ static int member_key(void *ctx, const char *key)
struct members *m = ctx;
char entry[32];
- if (strstr(m->keys, key))
+ if (str_contains(m->keys, key))
return -EEXIST;
if (strsprintf(entry, sizeof(entry), "%s=%d ", key,
m->slot->seen ? m->values : -1) < 0 ||
diff --git a/testing/unit/keepalive.c b/testing/unit/keepalive.c
index 023acc35..32bbafe1 100644
--- a/testing/unit/keepalive.c
+++ b/testing/unit/keepalive.c
@@ -288,7 +288,7 @@ static void expect_member(const struct keepalive_input *in, const char *want)
size_t len;
ASSERT_EQ(keepalive_emit(in, body, sizeof(body), &len), 0);
- UNIT_CHECK(0, strstr(body, want), "no %s in %s", want, body);
+ UNIT_CHECK(0, str_contains(body, want), "no %s in %s", want, body);
}
static void expect_refused(const struct keepalive_input *in, int ret)
diff --git a/testing/unit/kernel_abi.c b/testing/unit/kernel_abi.c
index 7f7a6551..59fb2f80 100644
--- a/testing/unit/kernel_abi.c
+++ b/testing/unit/kernel_abi.c
@@ -161,7 +161,7 @@ static void check(enum fixture fixture, int want_ok, const char *want)
return;
}
EXPECT_NE(ret, 0);
- UNIT_CHECK(0, strstr(detail, want), "detail \"%s\" lacks \"%s\"",
+ UNIT_CHECK(0, str_contains(detail, want), "detail \"%s\" lacks \"%s\"",
detail, want);
}
@@ -404,7 +404,7 @@ static void lsm_hooks_need_btf(void)
EXPECT_EQ(kernel_abi_validate_lsm_hooks(NULL, &hooks, detail,
sizeof(detail)), -EOPNOTSUPP);
- EXPECT_TRUE(strstr(detail, "kernel BTF is unavailable"));
+ EXPECT_TRUE(str_contains(detail, "kernel BTF is unavailable"));
}
static void needs_tpm_command(void)
diff --git a/testing/unit/unit.c b/testing/unit/unit.c
index 63ad639a..81c1934f 100644
--- a/testing/unit/unit.c
+++ b/testing/unit/unit.c
@@ -15,6 +15,8 @@
#include <sys/mman.h>
#include <sys/wait.h>
+#include <shirudo/string.h>
+
#include "unit.h"
#define UNIT_TIMEOUT 60
@@ -156,7 +158,7 @@ int main(int argc, char **argv)
}
printf("# %s\n", unit_suite.name);
for (const struct unit_case *c = unit_suite.cases; c->name; c++) {
- if (only && !strstr(c->name, only))
+ if (only && !str_contains(c->name, only))
continue;
failed += run_case(c, ++nr);
}
diff --git a/testing/unit/upatch_decode.c b/testing/unit/upatch_decode.c
index fbe9a91a..fd96ce38 100644
--- a/testing/unit/upatch_decode.c
+++ b/testing/unit/upatch_decode.c
@@ -194,7 +194,7 @@ static void decoder_error_is_sanitized(void)
ASSERT_EQ(lseek(capture, 0, SEEK_SET), 0);
len = read(capture, output, sizeof(output) - 1);
ASSERT_TRUE(len > 0);
- EXPECT_TRUE(strstr(output, "decoder failed: ?]0;title?\n"));
+ EXPECT_TRUE(str_contains(output, "decoder failed: ?]0;title?\n"));
EXPECT_FALSE(memchr(output, '\033', len));
EXPECT_EQ(close(capture), 0);
}
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index 98d6fd5d..8891bb82 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -469,7 +469,8 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)
bool array = s[1] == '[';
const char *start = s + (array ? 2 : 1);
const char *close = array ? "]]" : "]";
- const char *end = strstr(start, close);
+ const char *end = span_find(start, strlen(start),
+ close);
if (!end || end[strlen(close)])
return -EINVAL;
@@ -744,7 +745,7 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)
if (!r->symbol[0] || !r->input[0] ||
!r->n_generator || !r->n_update ||
- r->input[0] == '/' || strstr(r->input, "../") ||
+ r->input[0] == '/' || str_contains(r->input, "../") ||
!strcmp(r->input, ".."))
return -EINVAL;
}
@@ -827,7 +828,7 @@ static int build_resolve_source(const struct bpm_build_spec *spec,
{
char path[PATH_MAX];
- if (!source[0] || source[0] == '/' || strstr(source, "../") ||
+ if (!source[0] || source[0] == '/' || str_contains(source, "../") ||
!strcmp(source, ".."))
return -EINVAL;
if (strsprintf(path, sizeof(path), "%s/%s", spec->scope, source) < 0)
diff --git a/util/bpm_oci.c b/util/bpm_oci.c
index c7b221ac..c33ecf25 100644
--- a/util/bpm_oci.c
+++ b/util/bpm_oci.c
@@ -329,7 +329,7 @@ static int load_registry_auth(const char *registry, struct bpm_oci_client *c)
* member to occur in the same JSON object before accepting
* credentials.
*/
- p = strstr((char *)body, needle);
+ p = span_find((char *)body, strlen((char *)body), needle);
if (!p) {
xfree(body, body_len + 1);
return 0;
@@ -339,7 +339,7 @@ static int load_registry_auth(const char *registry, struct bpm_oci_client *c)
xfree(body, body_len + 1);
return -EINVAL;
}
- auth = strstr(p, "\"auth\"");
+ auth = span_find(p, strlen(p), "\"auth\"");
if (!auth || auth > end) {
xfree(body, body_len + 1);
return 0;
@@ -614,9 +614,9 @@ static int token_from_body(const char *body, char *out, size_t out_sz)
{
const char *token, *end;
- token = strstr(body, "\"token\"");
+ token = span_find(body, strlen(body), "\"token\"");
if (!token)
- token = strstr(body, "\"access_token\"");
+ token = span_find(body, strlen(body), "\"access_token\"");
if (token)
token = strchr(token, ':');
if (!token)
@@ -1082,7 +1082,7 @@ int bpm_oci_parse_pull_ref(const char *raw, struct bpm_oci_client *c,
memcpy(repository, slash + 1, colon - slash - 1);
repository[colon - slash - 1] = '\0';
bpm_copy_string(tag, tag_sz, colon + 1);
- if (strstr(repository, "//") || strchr(repository, '?') ||
+ if (str_contains(repository, "//") || strchr(repository, '?') ||
strchr(repository, '#') || strchr(repository, ':'))
return -EINVAL;
for (const char *part = repository; *part;) {
@@ -1123,8 +1123,8 @@ int bpm_oci_parse_push_repo(const char *raw, struct bpm_oci_client *c,
memcpy(endpoint, normalized, slash - normalized);
endpoint[slash - normalized] = '\0';
bpm_copy_string(repository, repository_sz, slash + 1);
- if (strchr(repository, ':') || strstr(repository, "//") ||
- strstr(repository, ".."))
+ if (strchr(repository, ':') || str_contains(repository, "//") ||
+ str_contains(repository, ".."))
return -EINVAL;
for (const char *part = repository; *part;) {
const char *end = strchr(part, '/');
@@ -1163,7 +1163,7 @@ int bpm_oci_parse_tree_repo(const char *raw, struct bpm_oci_client *c,
memcpy(endpoint, raw, (size_t)(slash - raw));
endpoint[slash - raw] = '\0';
bpm_copy_string(repository, repository_sz, slash + 1);
- if (strstr(repository, "..") || strstr(repository, "//") ||
+ if (str_contains(repository, "..") || str_contains(repository, "//") ||
strchr(repository, ':'))
return -EINVAL;
return bpm_oci_parse_endpoint(endpoint, c);
@@ -1193,8 +1193,8 @@ int bpm_trim(const char *in, char *out, size_t out_sz)
int bpm_oci_url(const struct bpm_oci_client *c, const char *repo,
const char *kind, const char *ref, char *out, size_t sz)
{
- if (strstr(repo, "..") || strstr(repo, "//") || strchr(repo, '?') ||
- strchr(repo, '#') || strstr(ref, "..") || strchr(ref, '/') ||
+ if (str_contains(repo, "..") || str_contains(repo, "//") || strchr(repo, '?') ||
+ strchr(repo, '#') || str_contains(ref, "..") || strchr(ref, '/') ||
strchr(ref, '?') || strchr(ref, '#'))
return -EINVAL;
if (strsprintf(out, sz, "%s/v2/%s/%s/%s", c->base_url, repo, kind, ref) < 0)
diff --git a/util/bpm_package.c b/util/bpm_package.c
index 32e4f966..7a63cf82 100644
--- a/util/bpm_package.c
+++ b/util/bpm_package.c
@@ -1027,7 +1027,7 @@ int bpm_tree_fetch_document(struct bpm_oci_client *c,
int nl = 0, ret;
if (!reference[0] || strchr(reference, '/') || strchr(reference, '?') ||
- strchr(reference, '#') || strstr(reference, ".."))
+ strchr(reference, '#') || str_contains(reference, ".."))
return -EINVAL;
ret = bpm_oci_url(c, repository, "manifests", reference, url,
sizeof(url));
diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.c
index 84f3b1fc..bd587fb9 100644
--- a/util/bpm_tree_state.c
+++ b/util/bpm_tree_state.c
@@ -216,7 +216,7 @@ static int selector_config_line(const char *line,
if (str_has_prefix(start, "# CONFIG_")) {
start += strlen("# ");
- eq = strstr(start, " is not set");
+ eq = span_find(start, strlen(start), " is not set");
if (!eq)
return 0;
*eq = '\0';
diff --git a/util/image_bootstrap.c b/util/image_bootstrap.c
index 8ae56fa3..f5bb6cea 100644
--- a/util/image_bootstrap.c
+++ b/util/image_bootstrap.c
@@ -21,8 +21,8 @@
bool image_path_valid(const char *path)
{
- return path && path[0] == '/' && !strstr(path, "/../") &&
- !strstr(path, "/./") && !strstr(path, "//") &&
+ return path && path[0] == '/' && !str_contains(path, "/../") &&
+ !str_contains(path, "/./") && !str_contains(path, "//") &&
strcmp(path, "/") &&
(strlen(path) < 3 || strcmp(path + strlen(path) - 3, "/.."));
}
diff --git a/util/image_config.c b/util/image_config.c
index de4662db..d80ab0a2 100644
--- a/util/image_config.c
+++ b/util/image_config.c
@@ -65,7 +65,7 @@ int image_open(enum image_path which, int flags)
int image_open_relative(const char *path, int flags)
{
- if (config_fd < 0 || !path || path[0] == '/' || strstr(path, ".."))
+ if (config_fd < 0 || !path || path[0] == '/' || str_contains(path, ".."))
return -EINVAL;
return open_beneath(config_fd, path, flags);
}
diff --git a/util/sysinfo.c b/util/sysinfo.c
index ef7a7a8e..8a26b178 100644
--- a/util/sysinfo.c
+++ b/util/sysinfo.c
@@ -272,7 +272,7 @@ int sysinfo_kernel_config_foreach(const char *kernel_release,
if (str_has_prefix(key, "# CONFIG_")) {
key += strlen("# ");
- not_set = strstr(key, " is not set");
+ not_set = span_find(key, strlen(key), " is not set");
if (!not_set ||
trim_config_text(not_set + strlen(" is not set"))[0] != '\0')
continue;