[vlc-devel] [PATCH] src: Avoid infinite loop

Edward Wang edward.c.wang at compdigitec.com
Sun Mar 25 00:37:52 CET 2012


"while (s != 0)" will never exit if haystack decreases

Close #6283
---
 Specifically, the problem occurs when vlc_strcasestr() tries to compare "\304rzte" and while (s != 0) never exits because "haystack += s;" combined with "s = -1" causes it to go backwards

 src/text/unicode.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/text/unicode.c b/src/text/unicode.c
index 789d0a1..8b06a35 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -235,6 +235,9 @@ char *vlc_strcasestr (const char *haystack, const char *needle)
         }
 
         s = vlc_towc (haystack, &(uint32_t) { 0 });
+        /* if s is negative (an invalid UTF-8 sequence), don't go backwards */
+        if (s < 0)
+            s = 1;
         haystack += s;
     }
     while (s != 0);
-- 
1.7.5.4




More information about the vlc-devel mailing list