From 03e9537331269442e0c2c3a59fe0b325cc4770a0 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 12 Dec 2013 13:44:06 -0800 Subject: [PATCH] Fix infinite loop in extension detection when the needle is a substring. We could keep examining the same ptr value over and over. --- src/dispatch_common.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index b8b9184..8d7c1d1 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -265,11 +265,15 @@ epoxy_extension_in_string(const char *extension_list, const char *ext) int len = strlen(ext); /* Make sure that don't just find an extension with our name as a prefix. */ - do { + while (true) { ptr = strstr(ptr, ext); - } while (ptr && (ptr[len] != ' ' && ptr[len] != 0)); + if (!ptr) + return false; - return ptr != NULL; + if (ptr[len] == ' ' || ptr[len] == 0) + return true; + ptr += len; + } } static bool