shithub: choc

Download patch

ref: 59bc6523b4869e515aefa9118715cd440b163fc4
parent: fe49cfc004026cdf92c58056079f68a01ba99c7f
author: Simon Howard <fraggle@gmail.com>
date: Sun Apr 18 14:48:48 EDT 2010

Fix unsigned integer overflow with calls to M_StrCaseStr where
strlen(haystack) < strlen(needle)

Subversion-branch: /branches/raven-branch
Subversion-revision: 1906

--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -263,12 +263,20 @@
 
 char *M_StrCaseStr(char *haystack, char *needle)
 {
+    unsigned int haystack_len;
     unsigned int needle_len;
     unsigned int len;
     unsigned int i;
 
+    haystack_len = strlen(haystack);
     needle_len = strlen(needle);
-    len = strlen(haystack) - needle_len;
+
+    if (haystack_len < needle_len)
+    {
+        return NULL;
+    }
+
+    len = haystack_len - needle_len;
 
     for (i = 0; i <= len; ++i)
     {