Skip to content

Commit dc45e40

Browse files
author
Tatiana Azundris Nuernberg
committed
Bug#20642505: HENRY SPENCER REGULAR EXPRESSIONS (REGEX) LIBRARY
The MySQL server uses Henry Spencer's library for regular expressions to support the REGEXP/RLIKE string operator. This changeset adapts a recent fix from the upstream for better 32-bit compatiblity. (Note that we cannot simply use the current upstream version as a drop-in replacement for the version used by the server as the latter has been extended to understand MySQL charsets etc.)
1 parent 820bf7b commit dc45e40

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

regex/regcomp.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/* Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
2+
See file COPYRIGHT for details.
3+
4+
This file was modified by Oracle on 2015-05-18 for 32-bit compatibility.
5+
6+
Modifications copyright (c) 2015, Oracle and/or its affiliates. All rights
7+
reserved. */
8+
19
#include <my_global.h>
210
#include <m_string.h>
311
#include <m_ctype.h>
@@ -133,12 +141,26 @@ CHARSET_INFO *charset;
133141
} else
134142
len = strlen((char *)pattern);
135143

144+
/*
145+
Find the maximum len we can safely process
146+
without a rollover and a mis-malloc.
147+
p->ssize is a sopno is a long (32+ bit signed);
148+
size_t is 16+ bit unsigned.
149+
*/
150+
{
151+
size_t new_ssize = len / (size_t)2 * (size_t)3 + (size_t)1; /* ugh */
152+
if ((new_ssize < len) || /* size_t rolled over */
153+
((SIZE_T_MAX / sizeof(sop)) < new_ssize) || /* malloc arg */
154+
(new_ssize > LONG_MAX)) /* won't fit in ssize */
155+
return(REG_ESPACE); /* MY_REG_ESPACE or MY_REG_INVARG */
156+
p->ssize = new_ssize;
157+
}
158+
136159
/* do the mallocs early so failure handling is easy */
137160
g = (struct re_guts *)malloc(sizeof(struct re_guts) +
138161
(NC-1)*sizeof(cat_t));
139162
if (g == NULL)
140163
return(REG_ESPACE);
141-
p->ssize = (long) (len/(size_t)2*(size_t)3 + (size_t)1); /* ugh */
142164
p->strip = (sop *)malloc(p->ssize * sizeof(sop));
143165
p->slen = 0;
144166
if (p->strip == NULL) {

0 commit comments

Comments
 (0)