aboutsummaryrefslogtreecommitdiffstats
path: root/main/dansguardian/dansguardian-2.10.1.1-pcre830.patch
blob: 0f96c3a9e2d98ac7c50731469ce90c513528cf58 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /bin/sh /usr/share/dpatch/dpatch-run
## 80_fix_libcre3_max_sub_expression_allocation.dpatch by Russell Coker
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: libpcre3 sets reg.re_nsub to an exreme large value and dansguardian
## DP: tries to allocate memory for all records which lets malloc fail.
## DP: this patch limits the allocation to 1024 records. (#667664)

@DPATCH@
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' pkg-dansguardian~/src/RegExp.cpp pkg-dansguardian/src/RegExp.cpp
--- pkg-dansguardian~/src/RegExp.cpp	2011-10-29 14:16:31.000000000 +0200
+++ pkg-dansguardian/src/RegExp.cpp	2012-06-23 11:02:48.821473711 +0200
@@ -161,14 +161,17 @@
 	offsets.clear();
 	lengths.clear();
 	imatched = false;
-	regmatch_t *pmatch = new regmatch_t[reg.re_nsub + 1];  // to hold result
+	int num_sub_expressions = MAX_SUB_EXPRESSIONS;
+	if(reg.re_nsub < num_sub_expressions)
+		num_sub_expressions = reg.re_nsub;
+	regmatch_t *pmatch = new regmatch_t[num_sub_expressions + 1];  // to hold result
 	if (!pmatch) {  // if it failed
 		delete[]pmatch;
 		imatched = false;
 		return false;
 		// exception?
 	}
-	if (regexec(&reg, pos, reg.re_nsub + 1, pmatch, 0)) {  // run regex
+	if (regexec(&reg, pos, num_sub_expressions + 1, pmatch, 0)) {  // run regex
 		delete[]pmatch;
 		imatched = false;
 //        #ifdef DGDEBUG
@@ -182,7 +185,7 @@
 	int error = 0;
 	while (error == 0) {
 		largestoffset = 0;
-		for (i = 0; i <= (signed) reg.re_nsub; i++) {
+		for (i = 0; i <= (signed) num_sub_expressions; i++) {
 			if (pmatch[i].rm_so != -1) {
 				matchlen = pmatch[i].rm_eo - pmatch[i].rm_so;
 				submatch = new char[matchlen + 1];
@@ -199,7 +202,7 @@
 		}
 		if (largestoffset > 0) {
 			pos += largestoffset;
-			error = regexec(&reg, pos, reg.re_nsub + 1, pmatch, REG_NOTBOL);
+			error = regexec(&reg, pos, num_sub_expressions + 1, pmatch, REG_NOTBOL);
 		} else {
 			error = -1;
 		}
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' pkg-dansguardian~/src/RegExp.hpp pkg-dansguardian/src/RegExp.hpp
--- pkg-dansguardian~/src/RegExp.hpp	2011-10-29 14:16:31.000000000 +0200
+++ pkg-dansguardian/src/RegExp.hpp	2012-06-23 11:02:48.821473711 +0200
@@ -22,6 +22,7 @@
 #ifndef __HPP_REGEXP
 #define __HPP_REGEXP
 
+#define MAX_SUB_EXPRESSIONS 1024
 
 // INCLUDES