Skip to content

eBPF-based security platform

bpm: check a fix ID without strspn()

Daniel Borkmann358751622229
diff --git a/testing/fuzz/fuzz-beefile.c b/testing/fuzz/fuzz-beefile.c
index 5435f45e..2a51630d 100644
--- a/testing/fuzz/fuzz-beefile.c
+++ b/testing/fuzz/fuzz-beefile.c
@@ -101,8 +101,11 @@ static void check_fixes(const struct bpm_fixes *fixes)
for (int i = 0; i < fixes->n; i++) {
const char *id = fixes->ids[i];
- if (!id[0] || id[strspn(id, FIX_ID_BYTES)])
+ if (!id[0])
abort();
+ for (const char *p = id; *p; p++)
+ if (!strchr(FIX_ID_BYTES, *p))
+ abort();
if (i && strcmp(fixes->ids[i - 1], id) >= 0)
abort();
}
diff --git a/testing/proofs/cbmc/bpm-beefile-fixes.c b/testing/proofs/cbmc/bpm-beefile-fixes.c
index ff817ba0..edc45c89 100644
--- a/testing/proofs/cbmc/bpm-beefile-fixes.c
+++ b/testing/proofs/cbmc/bpm-beefile-fixes.c
@@ -38,16 +38,7 @@ void pr_err(const char *fmt, ...)
{
}
-/* CBMC models neither strspn() nor qsort(). */
-size_t strspn(const char *s, const char *accept)
-{
- size_t n = 0;
-
- while (s[n] && strchr(accept, s[n]))
- n++;
- return n;
-}
-
+/* CBMC does not model qsort(). */
void qsort(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *))
{
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index 8d831882..98d6fd5d 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -305,7 +305,11 @@ static int build_parse_selector_kv(const char *key, const char *value,
bool bpm_fix_id_ok(const char *id)
{
- return id[0] && !id[strspn(id, BPM_FIX_ID_CHARS)];
+ size_t n = 0;
+
+ while (id[n] && strchr(BPM_FIX_ID_CHARS, id[n]))
+ n++;
+ return n && !id[n];
}
static int strings_compare(const void *left, const void *right)