eBPF-based security platform
coccinelle: follow the string helpers in the rules for bytes as strings
Daniel Borkmannab00297483a6
diff --git a/testing/ci-checks/t0006-check-coccinelle.sh b/testing/ci-checks/t0006-check-coccinelle.shindex 1a8cb539..32ee927f 100755--- a/testing/ci-checks/t0006-check-coccinelle.sh+++ b/testing/ci-checks/t0006-check-coccinelle.sh@@ -1055,6 +1055,15 @@ int member_walked(int fd)xfree(body, len + 1);return n;}++int id_searched(int fd)+{+ char id[64];++ if (read(fd, id, sizeof(id) - 1) <= 0)+ return -EIO;+ return str_contains(id, "x");+}EOF}@@ -1070,7 +1079,8 @@ test_expect_success 'the string rules report bytes taken for a string unchecked'grep -q "2 of 2 rules matched" "$W/err" &&grep -q "^read_unterminated: samples.c:7:" "$W/err" &&grep -q "^read_unterminated: samples.c:48:" "$W/err" &&- [ "$(grep -c "^read_unterminated: samples.c:" "$W/err")" = 2 ] &&+ grep -q "^read_unterminated: samples.c:117:" "$W/err" &&+ [ "$(grep -c "^read_unterminated: samples.c:" "$W/err")" = 3 ] &&grep -q "^file_as_string: samples.c:59:" "$W/err" &&grep -q "^file_as_string: samples.c:104:" "$W/err" &&[ "$(grep -c "^file_as_string: samples.c:" "$W/err")" = 2 ]diff --git a/testing/coccinelle/file_as_string.cocci b/testing/coccinelle/file_as_string.cocciindex 9c28b597..f36f8844 100644--- a/testing/coccinelle/file_as_string.cocci+++ b/testing/coccinelle/file_as_string.cocci@@ -18,8 +18,13 @@ attribute name SEC;expression buf, len, E, E1, E2, E3, E4, E5;identifier strfn = {strlen, strcmp, strcasecmp, strchr, strrchr, strstr,strcspn, strspn, strpbrk, strtok_r, strdup, xstrdup,- atoi, puts, hex_decode, sha256_digest_decode};-identifier second = {strscpy, strcmp, strcasecmp, strstr};+ atoi, puts, hex_decode, sha256_digest_decode,+ str_contains, str_equals_nocase, str_after_prefix,+ str_after_prefix_nocase, str_has_prefix,+ str_has_prefix_nocase};+identifier second = {strscpy, strcmp, strcasecmp, strstr, str_contains,+ str_equals_nocase, str_after_prefix,+ str_after_prefix_nocase};identifier f;position p1, p2;@@diff --git a/testing/coccinelle/read_unterminated.cocci b/testing/coccinelle/read_unterminated.cocciindex 150e056a..913eb751 100644--- a/testing/coccinelle/read_unterminated.cocci+++ b/testing/coccinelle/read_unterminated.cocci@@ -41,8 +41,13 @@ identifier rd3 = {read, pread, recv, readlink};identifier rd4 = {readlinkat, getxattr, lgetxattr, fgetxattr};identifier strfn = {strlen, strcmp, strcasecmp, strchr, strrchr, strstr,strcspn, strspn, strpbrk, strtok_r, strdup, xstrdup,- atoi, puts, hex_decode, sha256_digest_decode};-identifier second = {strscpy, strcmp, strcasecmp, strstr};+ atoi, puts, hex_decode, sha256_digest_decode,+ str_contains, str_equals_nocase, str_after_prefix,+ str_after_prefix_nocase, str_has_prefix,+ str_has_prefix_nocase};+identifier second = {strscpy, strcmp, strcasecmp, strstr, str_contains,+ str_equals_nocase, str_after_prefix,+ str_after_prefix_nocase};position p1 != {zeroed3.p, zeroed4.p};position p2;@@