summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2010-04-18 18:48:48 +0000
committerSimon Howard2010-04-18 18:48:48 +0000
commit59bc6523b4869e515aefa9118715cd440b163fc4 (patch)
treecf8f15db5c75c718655e96d1b0cba234487caf59
parentfe49cfc004026cdf92c58056079f68a01ba99c7f (diff)
downloadchocolate-doom-59bc6523b4869e515aefa9118715cd440b163fc4.tar.gz
chocolate-doom-59bc6523b4869e515aefa9118715cd440b163fc4.tar.bz2
chocolate-doom-59bc6523b4869e515aefa9118715cd440b163fc4.zip
Fix unsigned integer overflow with calls to M_StrCaseStr where
strlen(haystack) < strlen(needle) Subversion-branch: /branches/raven-branch Subversion-revision: 1906
-rw-r--r--src/m_misc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/m_misc.c b/src/m_misc.c
index 9d3144b2..ed41b5f1 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -263,12 +263,20 @@ void M_ForceUppercase(char *text)
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)
{