diff mbox series

[09/10] trace: Only permit explicit prefix matching for functions

Message ID 20240614081351.2088185-10-benjamin@sipsolutions.net
State Accepted
Headers show
Series Some ASAN/UBSAN related fixes | expand

Commit Message

Benjamin Berg June 14, 2024, 8:13 a.m. UTC
From: Benjamin Berg <benjamin.berg@intel.com>

The matching code currently only tests whether the prefix of a function
matches. Make this more strict by ensuring that the function name is not
longer.

However, as this breaks some tests (due to inlining), add the ability to
do an explicit prefix match by appending a '*' to the function name. Use
this to change the eap_eke_prf match to eap_eke_prf_* in order to match
one of the actual implementations.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
 src/utils/os_unix.c           | 8 +++++++-
 tests/hwsim/test_eap_proto.py | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c
index b665c79a25..66b4e42690 100644
--- a/src/utils/os_unix.c
+++ b/src/utils/os_unix.c
@@ -598,6 +598,7 @@  int testing_test_fail(const char *tag, bool is_alloc)
 	while (i < res) {
 		int allow_skip = 1;
 		int maybe = 0;
+		int prefix = 0;
 
 		if (*pos == '=') {
 			allow_skip = 0;
@@ -611,7 +612,12 @@  int testing_test_fail(const char *tag, bool is_alloc)
 			len = next - pos;
 		else
 			len = os_strlen(pos);
-		if (os_strncmp(pos, func[i], len) != 0) {
+		if (len >= 1 && pos[len - 1] == '*') {
+			prefix = 1;
+			len -= 1;
+		}
+		if (os_strncmp(pos, func[i], len) != 0 ||
+		    (!prefix && func[i][len] != '\0')) {
 			if (maybe && next) {
 				pos = next + 1;
 				continue;
diff --git a/tests/hwsim/test_eap_proto.py b/tests/hwsim/test_eap_proto.py
index 0aa292c371..f83611005d 100644
--- a/tests/hwsim/test_eap_proto.py
+++ b/tests/hwsim/test_eap_proto.py
@@ -2892,7 +2892,7 @@  def test_eap_proto_eke_errors(dev, apdev):
     tests = [(1, "eap_eke_dh_init", None),
              (1, "eap_eke_prf_hmac_sha1", "dhgroup=3 encr=1 prf=1 mac=1"),
              (1, "eap_eke_prf_hmac_sha256", "dhgroup=5 encr=1 prf=2 mac=2"),
-             (1, "eap_eke_prf", None),
+             (1, "eap_eke_prf_*", None),
              (1, "os_get_random;eap_eke_dhcomp", None),
              (1, "aes_128_cbc_encrypt;eap_eke_dhcomp", None),
              (1, "aes_128_cbc_decrypt;eap_eke_shared_secret", None),