Skip to content

Commit 88a8fca

Browse files
committed
Apply fix for potential heap overflow in PCRE code (CAN-2005-2491)
1 parent bf1da70 commit 88a8fca

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Modules/pypcre.c

+20-9
Original file line numberDiff line numberDiff line change
@@ -1163,14 +1163,30 @@ read_repeat_counts(const uschar *p, int *minp, int *maxp, const char **errorptr)
11631163
int min = 0;
11641164
int max = -1;
11651165

1166+
/* Read the minimum value and do a paranoid check: a negative value indicates
1167+
an integer overflow. */
1168+
11661169
while ((pcre_ctypes[*p] & ctype_digit) != 0) min = min * 10 + *p++ - '0';
1170+
if (min < 0 || min > 65535)
1171+
{
1172+
*errorptr = ERR5;
1173+
return p;
1174+
}
1175+
1176+
/* Read the maximum value if there is one, and again do a paranoid check
1177+
on its size. Also, max must not be less than min. */
11671178

11681179
if (*p == '}') max = min; else
11691180
{
11701181
if (*(++p) != '}')
11711182
{
11721183
max = 0;
11731184
while((pcre_ctypes[*p] & ctype_digit) != 0) max = max * 10 + *p++ - '0';
1185+
if (max < 0 || max > 65535)
1186+
{
1187+
*errorptr = ERR5;
1188+
return p;
1189+
}
11741190
if (max < min)
11751191
{
11761192
*errorptr = ERR4;
@@ -1179,16 +1195,11 @@ if (*p == '}') max = min; else
11791195
}
11801196
}
11811197

1182-
/* Do paranoid checks, then fill in the required variables, and pass back the
1183-
pointer to the terminating '}'. */
1198+
/* Fill in the required variables, and pass back the pointer to the terminating
1199+
'}'. */
11841200

1185-
if (min > 65535 || max > 65535)
1186-
*errorptr = ERR5;
1187-
else
1188-
{
1189-
*minp = min;
1190-
*maxp = max;
1191-
}
1201+
*minp = min;
1202+
*maxp = max;
11921203
return p;
11931204
}
11941205

0 commit comments

Comments
 (0)