chiark / gitweb /
ed5b5c17b5e82fe21fcbc09b1791dc789bc44154
[pcre3.git] / debian / patches / Fix-bad-compilation-for-patterns-like-1-1-with-forwa.patch
1 Description: CVE-2015-2326: heap buffer overflow in pcre_compile2()
2  Fix bad compilation for patterns like /((?+1)(\1))/ with
3  forward reference subroutine and recursive back reference within the same
4  group.
5 Origin: upstream, http://vcs.pcre.org/pcre?view=revision&revision=1529
6 Bug: http://bugs.exim.org/show_bug.cgi?id=1592
7 Bug-Debian: https://bugs.debian.org/783285
8 Forwarded: not-needed
9 Last-Update: 2015-09-10
10 Applied-Upstream: 8.36
11
12 --- a/pcre_compile.c
13 +++ b/pcre_compile.c
14 @@ -8027,6 +8027,7 @@ int length;
15  unsigned int orig_bracount;
16  unsigned int max_bracount;
17  branch_chain bc;
18 +size_t save_hwm_offset;
19  
20  /* If set, call the external function that checks for stack availability. */
21  
22 @@ -8044,6 +8045,8 @@ bc.current_branch = code;
23  firstchar = reqchar = 0;
24  firstcharflags = reqcharflags = REQ_UNSET;
25  
26 +save_hwm_offset = cd->hwm - cd->start_workspace;
27 +
28  /* Accumulate the length for use in the pre-compile phase. Start with the
29  length of the BRA and KET and any extra bytes that are required at the
30  beginning. We accumulate in a local variable to save frequent testing of
31 @@ -8246,7 +8249,7 @@ for (;;)
32          {
33          *code = OP_END;
34          adjust_recurse(start_bracket, 1 + LINK_SIZE,
35 -          (options & PCRE_UTF8) != 0, cd, cd->hwm - cd->start_workspace);
36 +          (options & PCRE_UTF8) != 0, cd, save_hwm_offset);
37          memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
38            IN_UCHARS(code - start_bracket));
39          *start_bracket = OP_ONCE;
40 --- a/testdata/testinput11
41 +++ b/testdata/testinput11
42 @@ -134,4 +134,6 @@ is required for these tests. --/
43  
44  /(((a\2)|(a*)\g<-1>))*a?/B
45  
46 +/((?+1)(\1))/B
47 +
48  /-- End of testinput11 --/
49 --- a/testdata/testinput2
50 +++ b/testdata/testinput2
51 @@ -4066,4 +4066,6 @@ backtracking verbs. --/
52  
53  "((?2){0,1999}())?"
54  
55 +/((?+1)(\1))/BZ
56 +
57  /-- End of testinput2 --/
58 --- a/testdata/testoutput11-16
59 +++ b/testdata/testoutput11-16
60 @@ -733,4 +733,19 @@ Memory allocation (code space): 14
61   41     End
62  ------------------------------------------------------------------
63  
64 +/((?+1)(\1))/B
65 +------------------------------------------------------------------
66 +  0  20 Bra
67 +  2  16 Once
68 +  4  12 CBra 1
69 +  7   9 Recurse
70 +  9   5 CBra 2
71 + 12     \1
72 + 14   5 Ket
73 + 16  12 Ket
74 + 18  16 Ket
75 + 20  20 Ket
76 + 22     End
77 +------------------------------------------------------------------
78 +
79  /-- End of testinput11 --/
80 --- a/testdata/testoutput11-32
81 +++ b/testdata/testoutput11-32
82 @@ -733,4 +733,19 @@ Memory allocation (code space): 28
83   41     End
84  ------------------------------------------------------------------
85  
86 +/((?+1)(\1))/B
87 +------------------------------------------------------------------
88 +  0  20 Bra
89 +  2  16 Once
90 +  4  12 CBra 1
91 +  7   9 Recurse
92 +  9   5 CBra 2
93 + 12     \1
94 + 14   5 Ket
95 + 16  12 Ket
96 + 18  16 Ket
97 + 20  20 Ket
98 + 22     End
99 +------------------------------------------------------------------
100 +
101  /-- End of testinput11 --/
102 --- a/testdata/testoutput11-8
103 +++ b/testdata/testoutput11-8
104 @@ -733,4 +733,19 @@ Memory allocation (code space): 10
105   60     End
106  ------------------------------------------------------------------
107  
108 +/((?+1)(\1))/B
109 +------------------------------------------------------------------
110 +  0  31 Bra
111 +  3  25 Once
112 +  6  19 CBra 1
113 + 11  14 Recurse
114 + 14   8 CBra 2
115 + 19     \1
116 + 22   8 Ket
117 + 25  19 Ket
118 + 28  25 Ket
119 + 31  31 Ket
120 + 34     End
121 +------------------------------------------------------------------
122 +
123  /-- End of testinput11 --/
124 --- a/testdata/testoutput2
125 +++ b/testdata/testoutput2
126 @@ -14175,4 +14175,19 @@ Failed: parentheses are too deeply neste
127  
128  "((?2){0,1999}())?"
129  
130 +/((?+1)(\1))/BZ
131 +------------------------------------------------------------------
132 +        Bra
133 +        Once
134 +        CBra 1
135 +        Recurse
136 +        CBra 2
137 +        \1
138 +        Ket
139 +        Ket
140 +        Ket
141 +        Ket
142 +        End
143 +------------------------------------------------------------------
144 +
145  /-- End of testinput2 --/