From: Yonggang Luo <[email protected]>

Replace the GNU-specific memmem() call with a bounded memcmp()
search. Preserve binary BIOS scanning across embedded NUL bytes
without relying on a function unavailable on MinGW.

Signed-off-by: Yonggang Luo <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
Tested-by: Eric Farman <[email protected]>
Link: 
https://lore.kernel.org/qemu-devel/[email protected]
Signed-off-by: Pierrick Bouvier <[email protected]>
---
 tests/qtest/pxe-test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/pxe-test.c b/tests/qtest/pxe-test.c
index 61c92a2df45..37d74d7ee09 100644
--- a/tests/qtest/pxe-test.c
+++ b/tests/qtest/pxe-test.c
@@ -111,10 +111,18 @@ static bool s390_bios_has_string(const char *needle)
 {
     const char *contents;
     gsize len;
-    bool found;
+    size_t needle_len = strlen(needle);
+    bool found = false;
 
     contents = s390_bios_load(&len);
-    found = memmem(contents, len, needle, strlen(needle)) != NULL;
+    if (needle_len <= len) {
+        for (gsize i = 0; i <= len - needle_len; i++) {
+            if (memcmp(contents + i, needle, needle_len) == 0) {
+                found = true;
+                break;
+            }
+        }
+    }
 
     g_test_message("\"%s\" %s in bios", needle, found ? "found" : "not found");
     return found;
-- 
2.43.0


Reply via email to