File: CVE-2015-2305.patch

package info (click to toggle)
php5 5.3.3.1-7%2Bsqueeze29
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 123,520 kB
  • ctags: 55,742
  • sloc: ansic: 633,963; php: 19,620; sh: 11,344; xml: 5,816; cpp: 2,400; yacc: 1,745; exp: 1,514; makefile: 1,019; pascal: 623; awk: 537; sql: 22
file content (30 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Index: php5-5.3.3.1/ext/ereg/regex/regcomp.c
===================================================================
--- php5-5.3.3.1.orig/ext/ereg/regex/regcomp.c	2016-01-21 15:43:49.000000000 +0100
+++ php5-5.3.3.1/ext/ereg/regex/regcomp.c	2016-01-24 13:48:03.000000000 +0100
@@ -117,7 +117,25 @@
 							(NC-1)*sizeof(cat_t));
 	if (g == NULL)
 		return(REG_ESPACE);
+
+        /*
+         * Limit the pattern space to avoid a 32-bit overflow on buffer
+         * extension.  Also avoid any signed overflow in case of conversion
+         * so make the real limit based on a 31-bit overflow.
+         *
+         * Likely not applicable on 64-bit systems but handle the case
+         * generically (who are we to stop people from using ~715MB+
+         * patterns?).
+         */
+        size_t maxlen = ((size_t)-1 >> 1) / sizeof(sop) * 2 / 3;
+        if (len >= maxlen) {
+                free((char *)g);
+                return(REG_ESPACE);
+        }
+
 	p->ssize = len/(size_t)2*(size_t)3 + (size_t)1;	/* ugh */
+        assert(p->ssize >= len);
+
 	p->strip = (sop *)malloc(p->ssize * sizeof(sop));
 	p->slen = 0;
 	if (p->strip == NULL) {